|
Well, I'd love to help, but seeing as you didn't post any code, I have no idea what you did wrong.
You should be storing the zoom for both images in one variable, so it's in sync
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
this is the code in user Control
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Data;<br />
using System.Windows.Forms;<br />
using System.Drawing.Imaging;<br />
<br />
namespace SynchronizingImages<br />
{<br />
<br />
[System.Runtime.InteropServices.ComVisible(false)]<br />
public class ucSynchImages: System.Windows.Forms.UserControl<br />
{<br />
<br />
private System.ComponentModel.Container components = null;<br />
private System.Windows.Forms.MouseButtons m_MouseButtons = System.Windows.Forms.MouseButtons.Left;<br />
<br />
private System.Drawing.Bitmap m_OriginalImage;<br />
<br />
private System.Drawing.Point m_StartPoint;<br />
private System.Drawing.Point m_Origin = new System.Drawing.Point(0, 0);<br />
<br />
private Graphics g;<br />
public System.Drawing.Rectangle SrcRect;<br />
public System.Drawing.Rectangle DestRect;<br />
<br />
private bool m_ZoomOnMouseWheel = true;<br />
private double m_ZoomFactor = 1.0;<br />
<br />
<br />
private int m_DrawWidth;<br />
private int m_DrawHeight;<br />
<br />
private Point m_centerpoint;<br />
<br />
private bool m_PanMode = true;<br />
private bool m_StretchImageToFit = false;<br />
<br />
private Rectangle m_Select_Rect;<br />
<br />
private Point EndPoint;<br />
<br />
<br />
<br />
#region " Windows Form Designer generated code "<br />
<br />
protected override void Dispose(bool disposing)<br />
{<br />
if (disposing) <br />
{<br />
if ((components != null)) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose(disposing);<br />
}<br />
<br />
<br />
<br />
[System.Diagnostics.DebuggerStepThrough()]<br />
private void InitializeComponent()<br />
{<br />
this.Name = "ucSynchImages";<br />
<br />
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ucSynchImages_MouseMove);<br />
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.ucSynchImages_MouseWheel);<br />
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ucSynchImages_MouseDown);<br />
<br />
}<br />
<br />
#endregion<br />
<br />
#region "Public/Private Shadows"<br />
public System.Drawing.Image image <br />
{<br />
get { return m_OriginalImage; }<br />
set <br />
{<br />
if ((m_OriginalImage != null)) <br />
{<br />
m_OriginalImage.Dispose();<br />
m_Select_Rect =Rectangle.Empty ;<br />
m_Origin = new Point(0, 0);<br />
m_ZoomFactor = 1;<br />
GC.Collect();<br />
<br />
}<br />
<br />
if (value == null) <br />
{<br />
m_OriginalImage = null;<br />
this.Invalidate();<br />
return;
}<br />
<br />
Rectangle r = new Rectangle(0, 0, value.Width, value.Height);<br />
m_OriginalImage = new Bitmap(value);<br />
BitmapData bmpData = new BitmapData();<br />
m_OriginalImage = (Bitmap)m_OriginalImage.Clone(r,System .Drawing . Imaging.PixelFormat.Format32bppPArgb);<br />
<br />
this.Invalidate();<br />
}<br />
}<br />
<br />
#endregion<br />
#region "Protected Overrides"<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
e.Graphics.Clear(this.BackColor);<br />
DrawImage(e.Graphics);<br />
base.OnPaint(e);<br />
}<br />
protected override void OnSizeChanged(EventArgs e)<br />
{<br />
DestRect = new System.Drawing.Rectangle(0, 0, ClientSize.Width, ClientSize.Height);<br />
ComputeDrawingArea();<br />
base.OnSizeChanged(e);<br />
}<br />
#endregion<br />
#region "Public Properties"<br />
public void ZoomIn()<br />
{<br />
ZoomImage(true);<br />
}<br />
<br />
public void ZoomOut()<br />
{<br />
ZoomImage(false);<br />
}<br />
private void ZoomImage(bool ZoomIn)<br />
{<br />
<br />
m_centerpoint=new Point(m_Origin.X + SrcRect.Width / 2,m_Origin.Y + SrcRect.Height / 2);<br />
if (ZoomIn) <br />
{<br />
ZoomFactor = Math.Round(ZoomFactor * 1.1, 2);<br />
}<br />
else <br />
{<br />
ZoomFactor = Math.Round(ZoomFactor * 0.9, 2);<br />
}<br />
m_Origin.X = Convert .ToInt32 (m_centerpoint.X - ClientSize.Width / m_ZoomFactor / 2);<br />
m_Origin.Y =Convert .ToInt32( m_centerpoint.Y - ClientSize.Height / m_ZoomFactor / 2);<br />
CheckBounds();<br />
}<br />
public System.Windows.Forms.MouseButtons PanButton <br />
{<br />
get { return m_MouseButtons; }<br />
set { m_MouseButtons = value; }<br />
}<br />
public bool ZoomOnMouseWheel <br />
{<br />
get { return m_ZoomOnMouseWheel; }<br />
set { m_ZoomOnMouseWheel = value; }<br />
}<br />
public double ZoomFactor <br />
{<br />
get { return m_ZoomFactor; }<br />
set <br />
{<br />
m_ZoomFactor = value;<br />
if (m_ZoomFactor > 15)<br />
m_ZoomFactor = 15;<br />
if (m_ZoomFactor < 0.05)<br />
m_ZoomFactor = 0.05;<br />
if ((m_OriginalImage != null)) <br />
{<br />
ComputeDrawingArea();<br />
CheckBounds();<br />
}<br />
this.Invalidate();<br />
}<br />
}<br />
<br />
<br />
public bool PanMode <br />
{<br />
get { return m_PanMode; }<br />
set { m_PanMode = value; }<br />
}<br />
<br />
<br />
#endregion<br />
<br />
<br />
private void DrawImage( Graphics g)<br />
{<br />
if (m_OriginalImage == null)<br />
return;
g.PixelOffsetMode = System.Drawing.Drawing2D .PixelOffsetMode.Half;<br />
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;<br />
g.InterpolationMode =System.Drawing. Drawing2D.InterpolationMode.NearestNeighbor;<br />
<br />
<br />
if (m_StretchImageToFit) <br />
{<br />
SrcRect = new System.Drawing.Rectangle(0, 0, m_OriginalImage.Width, m_OriginalImage.Height);<br />
}<br />
else <br />
{<br />
SrcRect = new System.Drawing.Rectangle(m_Origin.X, m_Origin.Y, m_DrawWidth, m_DrawHeight);<br />
}<br />
<br />
g.DrawImage(m_OriginalImage, DestRect, SrcRect, GraphicsUnit.Pixel);<br />
<br />
<br />
}<br />
<br />
private void ComputeDrawingArea()<br />
{<br />
<br />
m_DrawHeight = Convert .ToInt32 (this.Height / m_ZoomFactor);<br />
m_DrawWidth = Convert .ToInt32 (this.Width / m_ZoomFactor);<br />
<br />
}<br />
<br />
private void CheckBounds()<br />
{<br />
if (m_OriginalImage == null)<br />
return;
<br />
if (m_Origin.X < 0)<br />
m_Origin.X = 0;<br />
if (m_Origin.Y < 0)<br />
m_Origin.Y = 0;<br />
if (m_Origin.X > m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor)) <br />
{<br />
m_Origin.X = Convert .ToInt32(m_OriginalImage.Width - (ClientSize.Width / m_ZoomFactor));<br />
}<br />
if (m_Origin.Y > m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor)) <br />
{<br />
m_Origin.Y =Convert .ToInt32( m_OriginalImage.Height - (ClientSize.Height / m_ZoomFactor));<br />
}<br />
<br />
if (m_Origin.X < 0)<br />
m_Origin.X = 0;<br />
if (m_Origin.Y < 0)<br />
m_Origin.Y = 0;<br />
}<br />
<br />
<br />
<br />
public ucSynchImages()<br />
{<br />
<br />
InitializeComponent();<br />
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
this.SetStyle(ControlStyles.DoubleBuffer, true);<br />
}<br />
<br />
<br />
public void ucSynchImages_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if (m_OriginalImage == null)<br />
return;
<br />
if (e.Button == m_MouseButtons) <br />
{<br />
<br />
int DeltaX = m_StartPoint.X - e.X;<br />
int DeltaY = m_StartPoint.Y - e.Y;<br />
<br />
if (PanMode) <br />
{<br />
m_Origin.X = Convert .ToInt32 (m_Origin.X + (DeltaX / m_ZoomFactor));<br />
m_Origin.Y = Convert .ToInt32(m_Origin.Y + (DeltaY / m_ZoomFactor));<br />
CheckBounds();<br />
m_StartPoint.X = e.X;<br />
m_StartPoint.Y = e.Y;<br />
this.Invalidate();<br />
<br />
}<br />
}<br />
}<br />
<br />
private void ucSynchImages_MouseWheel(object sender, MouseEventArgs e)<br />
{<br />
if (!ZoomOnMouseWheel)<br />
return;
<br />
if (e.Delta > 0) <br />
{<br />
ZoomImage(true);<br />
}<br />
else if (e.Delta < 0) <br />
{<br />
ZoomImage(false);<br />
}<br />
}<br />
<br />
public void ucSynchImages_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (m_OriginalImage == null)<br />
return;
EndPoint = Point.Empty ;<br />
m_StartPoint = new Point(e.X, e.Y);<br />
this.Focus();<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
}<br />
|
|
|
|
|
code in form
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace SynchronizingImages<br />
{<br />
public class SynchImage : System.Windows.Forms.Form<br />
{<br />
private SynchronizingImages.ucSynchImages ucSynchImages1;<br />
private SynchronizingImages.ucSynchImages ucSynchImages2;<br />
private System.Windows.Forms.Button btnOpen;<br />
private System.Windows.Forms.OpenFileDialog ofd1;<br />
private System.Windows.Forms.Button btnopen2;<br />
Bitmap bp,bp1;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public SynchImage()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.ucSynchImages1 = new SynchronizingImages.ucSynchImages();<br />
this.ucSynchImages2 = new SynchronizingImages.ucSynchImages();<br />
this.btnOpen = new System.Windows.Forms.Button();<br />
this.ofd1 = new System.Windows.Forms.OpenFileDialog();<br />
this.btnopen2 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.ucSynchImages1.Cursor = System.Windows.Forms.Cursors.Hand;<br />
this.ucSynchImages1.image = null;<br />
this.ucSynchImages1.Location = new System.Drawing.Point(56, 40);<br />
this.ucSynchImages1.Name = "ucSynchImages1";<br />
this.ucSynchImages1.PanButton = System.Windows.Forms.MouseButtons.Left;<br />
this.ucSynchImages1.PanMode = true;<br />
this.ucSynchImages1.Size = new System.Drawing.Size(304, 312);<br />
this.ucSynchImages1.TabIndex = 0;<br />
this.ucSynchImages1.ZoomFactor = 1;<br />
this.ucSynchImages1.ZoomOnMouseWheel = true;<br />
this.ucSynchImages1.Load += new System.EventHandler(this.ucSynchImages1_Load);<br />
this.ucSynchImages2.Cursor = System.Windows.Forms.Cursors.Hand;<br />
this.ucSynchImages2.image = null;<br />
this.ucSynchImages2.Location = new System.Drawing.Point(456, 40);<br />
this.ucSynchImages2.Name = "ucSynchImages2";<br />
this.ucSynchImages2.PanButton = System.Windows.Forms.MouseButtons.Left;<br />
this.ucSynchImages2.PanMode = true;<br />
this.ucSynchImages2.Size = new System.Drawing.Size(304, 312);<br />
this.ucSynchImages2.TabIndex = 1;<br />
this.ucSynchImages2.ZoomFactor = 1;<br />
this.ucSynchImages2.ZoomOnMouseWheel = true;<br />
this.btnOpen.Cursor = System.Windows.Forms.Cursors.Hand;<br />
this.btnOpen.Location = new System.Drawing.Point(168, 384);<br />
this.btnOpen.Name = "btnOpen";<br />
this.btnOpen.TabIndex = 2;<br />
this.btnOpen.Text = "Open";<br />
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);<br />
this.btnopen2.Cursor = System.Windows.Forms.Cursors.Hand;<br />
this.btnopen2.Location = new System.Drawing.Point(544, 384);<br />
this.btnopen2.Name = "btnopen2";<br />
this.btnopen2.TabIndex = 3;<br />
this.btnopen2.Text = "Open2";<br />
this.btnopen2.Click += new System.EventHandler(this.btnopen2_Click);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.BackColor = System.Drawing.Color.White;<br />
this.ClientSize = new System.Drawing.Size(864, 502);<br />
this.Controls.Add(this.btnopen2);<br />
this.Controls.Add(this.btnOpen);<br />
this.Controls.Add(this.ucSynchImages2);<br />
this.Controls.Add(this.ucSynchImages1);<br />
this.Name = "SynchImage";<br />
this.Text = "SynchronizingImages";<br />
this.Load += new System.EventHandler(this.SynchImage_Load);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new SynchImage());<br />
}<br />
<br />
<br />
<br />
private void btnOpen_Click(object sender, System.EventArgs e)<br />
{<br />
ofd1.ShowDialog();<br />
if(ofd1.FileName !="")<br />
{<br />
bp=new Bitmap(ofd1.FileName);<br />
ucSynchImages1.image=bp;<br />
if(ofd1.FileName!="")<br />
{<br />
ucSynchImages2 .image =bp1;<br />
ucSynchImages1.Size =ucSynchImages2 .Size ;<br />
}<br />
<br />
}<br />
}<br />
<br />
private void SynchImage_Load(object sender, System.EventArgs e)<br />
{<br />
ucSynchImages1.MouseDown+=new MouseEventHandler(ucSynchImages1_MouseDown);<br />
ucSynchImages1.MouseMove+=new MouseEventHandler(ucSynchImages1_MouseMove);<br />
ucSynchImages1.MouseWheel+=new MouseEventHandler(ucSynchImages1_MouseWheel);<br />
ucSynchImages2.MouseDown+=new MouseEventHandler(ucSynchImages2_MouseDown);<br />
ucSynchImages2.MouseMove+=new MouseEventHandler(ucSynchImages2_MouseMove);<br />
ucSynchImages2.MouseWheel+=new MouseEventHandler(ucSynchImages2_MouseWheel);<br />
<br />
}<br />
private void ucSynchImages1_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
ucSynchImages2.ucSynchImages_MouseDown (sender,e);<br />
}<br />
<br />
private void ucSynchImages1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
ucSynchImages2.ucSynchImages_MouseMove (sender,e);<br />
}<br />
<br />
private void ucSynchImages1_MouseWheel(object sender, MouseEventArgs e)<br />
{<br />
<br />
<br />
if(e.Delta >0)<br />
{<br />
ucSynchImages2.SrcRect=ucSynchImages1.SrcRect;<br />
ucSynchImages2.DestRect=ucSynchImages1.DestRect;<br />
<br />
ucSynchImages2.ZoomIn();<br />
<br />
<br />
<br />
}<br />
if(e.Delta <0)<br />
{<br />
ucSynchImages2.SrcRect=ucSynchImages1.SrcRect;<br />
ucSynchImages2.DestRect=ucSynchImages1.DestRect;<br />
<br />
ucSynchImages2 .ZoomOut();<br />
<br />
<br />
}<br />
}<br />
<br />
private void ucSynchImages2_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
ucSynchImages1 .Size =ucSynchImages2 .Size ;<br />
ucSynchImages1.ucSynchImages_MouseDown (sender,e);<br />
}<br />
<br />
private void ucSynchImages2_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
ucSynchImages1 .Size =ucSynchImages2 .Size ;<br />
ucSynchImages1.ucSynchImages_MouseMove (sender,e);<br />
}<br />
<br />
private void ucSynchImages2_MouseWheel(object sender, MouseEventArgs e)<br />
{<br />
ucSynchImages2 .Size =ucSynchImages1 .Size ;<br />
<br />
if(e.Delta >0)<br />
{<br />
ucSynchImages2.SrcRect=ucSynchImages1.SrcRect;<br />
ucSynchImages2.DestRect=ucSynchImages1.DestRect;<br />
ucSynchImages1.ZoomIn();<br />
ucSynchImages2.Size =ucSynchImages1.Size ;<br />
<br />
<br />
}<br />
if(e.Delta <0)<br />
{<br />
ucSynchImages2.SrcRect=ucSynchImages1.SrcRect;<br />
ucSynchImages2.DestRect=ucSynchImages1.DestRect;<br />
ucSynchImages1.ZoomOut();<br />
ucSynchImages2.Size =ucSynchImages1.Size ;<br />
<br />
<br />
}<br />
}<br />
<br />
private void btnopen2_Click(object sender, System.EventArgs e)<br />
{<br />
ofd1.ShowDialog();<br />
if(ofd1.FileName !="")<br />
{<br />
bp1=new Bitmap(ofd1.FileName);<br />
ucSynchImages2.image=bp1;<br />
ucSynchImages1 .image =bp;<br />
ucSynchImages2.Size =ucSynchImages1 .Size ;<br />
<br />
}<br />
<br />
}<br />
<br />
private void ucSynchImages1_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
|
|
|
|
|
B.rekha wrote: // btnopen2
//
this.btnopen2.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnopen2.Location = new System.Drawing.Point(544, 384);
this.btnopen2.Name = "btnopen2";
this.btnopen2.TabIndex = 3;
this.btnopen2.Text = "Open2";
this.btnopen2.Click += new System.EventHandler(this.btnopen2_Click);
//
// SynchImage
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(864, 502);
this.Controls.Add(this.btnopen2);
this.Controls.Add(this.btnOpen);
this.Controls.Add(this.ucSynchImages2);
this.Controls.Add(this.ucSynchImages1);
this.Name = "SynchImage";
this.Text = "SynchronizingImages";
this.Load += new System.EventHandler(this.SynchImage_Load);
this.ResumeLayout(false);
I assume you realise that this code is auto generated. I kind of meant just the pertinent code that you actually wrote.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
actually we have posted every thing,that is why you confused , and you can observe the remaining things
in user control, and form code.
Thank you for your quick response.
|
|
|
|
|
I know what you did, I was asking why you couldn't take the time to create a post where I didn't have to read two huge posts looking for the little bits that are pertinent to the problem.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
When I coding C# language to connect SQL Server and then. I write stored procedure to insert into table, and I want to show data immediately in datagridview in form and orthers controls.
So that, I want to coding procedure or function with C# to refresh datatabase name.
Who can help me?
If posible I thanks so much.
For example:
I using: Namespace
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
Function:
Server srv = new Server();
Database db = srv.Databases["Database_name"];
db.Refresh();
Thanks
Best & Regards
DFGDFGDFG
|
|
|
|
|
Hello
I have the simple code bellow with 1 datatable and two dgv
one DGV is defined at runtime as show the other one is defined empty at design time the first does not fill the second yes
What can be the cause ?
DataGridView tmpDGV = new DataGridView();<br />
<br />
tmpDGV.DataSource = dt;<br />
dgv_addr.DataSource = dt;
Thank you for any help
|
|
|
|
|
baranils wrote: one DGV is defined at runtime as show the other one is defined empty at design time the first does not fill the second yes
???, your question isnt proper, however if you wanna add DGV at runtime, then you will need to add it in the form else it wont show up
code to add control in form :
this.Controls.Add(tmpDGV);
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thank you
Yes I miss that !
|
|
|
|
|
Hello
One little thing : my intent was not tho show the DGV but to fill it with a datasource to print it with another control
Anyway the problem is the same : if the DGV is not added to the form, the Datasource has no effect.
Thank you
|
|
|
|
|
Hi! I have a data table called maps that had been bind to a list view. I would like to add an event to the list view that is onSelectionChange. Inside this event, when user make a new selection I will display the selected data out into a detail view. Does anyone know how to do this by using listview.SelectedValue? I am building whole thing in wpf and c#. Thanks for your help.
I had try out this code but it always return -1.
DataView view = new DataView(maps);
view.Sort = "mapTitle";
MessageBox.Show(view.Find(mapListView.SelectedValue).ToString());
|
|
|
|
|
Hi,
you have to register for event and create method that will handle that event.
Method could look like this:
void mapListView_SelectionChanged(object sender, SelectionChangedEventArgs e)<br />
{<br />
}
and you have to tell mapListView to call your method. you can do it in xaml like this:
<ListView Name="mapListView" SelectionChanged="listView1_SelectionChanged"
or programatically (after mapListView is created and initialized):
this.listView1.SelectionChanged += new SelectionChangedEventHandler(listView1_SelectionChanged);
|
|
|
|
|
yuenli wrote: I would like to add an event to the list view that is onSelectionChange
why you arnt using SelectedIndexChanged ? its same
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
When I try to perform the math below I get an answer of 0, but the result of the below should be 5.76
Int64 lpTotalNumberOfFreeBytes = 41085476864;
Int64 lpTotalNumberOfBytes = 712212955136;
Int64 strAnswer = ((lpTotalNumberOfFreeBytes / lpTotalNumberOfBytes) * 100);
Does anyone see what I am doing wrong here?
Thanks
|
|
|
|
|
hi,
int/int performs an integer division; you should consider one of these fixes:
- use float or double everywhere
- postpone division, hence do 100*int/int instead of int/int*100
(there is an increased risk of overflowing when doing all multiplies before all divides)
The above holds true in most programming languages (C, C++, Java, C#, ...).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
You can use float everywhere as Luc adviced you. But if you for some reason need to store lpTotalNumberOfFreeBytes and lpTotalNumberOfBytes as Int64 you can covert their values in division expression like this:
((float)lpTotalNumberOfFreeBytes / (float)lpTotalNumberOfBytes )*100;
However this expression return float value so you need to change type of strAnswer from Int64 to float or convert explicitly convert result to Int64:
Int64 strAnswer = (Int64) (((float)lpTotalNumberOfFreeBytes / (float)lpTotalNumberOfBytes )*100);
But remember if you convert float to Int64 system will cut off everything behind decimal point, so in this particular case result 5.7687068 will be converted to 5.
hth
|
|
|
|
|
Hello..
I've got an InvalidOperationException: invalid Value vor the OracleObjectMappingAttribute nNR
Could NET have a problem with casting NUMBER to int? Or have i to do something
special, because I'm using a OUT-only Parameter?
Here are my code:
PLSQL:
-------------
create type TESTOBJ as OBJECT (
nNR NUMBER;
sTEXT VARCHAR2(20);
)
create testproc(p_testobj OUT TESTOBJ)
as
v_testobj TESTOBJ := TESTOBJ(1,'Test');
begin
p_testobj := v_testobj;
end;
C# the Mapped OBj:
-------------------------------
public class OracleXTBQueueObj : IOracleCustomType
{
private int nr;
[OracleObjectMappingAttribute("nNR")]
public int NR {
get { return nr; }
set { nr = value; }
}
private string tEXT;
[OracleObjectMappingAttribute("sTEXT")]
public string TEXT
{
get { return tEXT; }
set { tEXT = value; }
}
public virtual void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "nNR", this.NR);
OracleUdt.SetValue(con, pUdt, "sTEXT", this.TEXT);
}
public virtual void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
this.NR = ((int)(OracleUdt.GetValue(con, pUdt, "nNR")));
this.TEXT = ((string)(OracleUdt.GetValue(con, pUdt, "sTEXT")));
}
}
C# the Factory:
-------------------------------
[OracleCustomTypeMappingAttribute("USR.TESTOBJ")]
public class OracleXTBQueueObjFactory : IOracleCustomTypeFactory
{
public IOracleCustomType CreateObject()
{
OracleXTBQueueObj obj = new OracleXTBQueueObj();
return obj;
}
}
C# the function, callin the PROCEDURE:
------------------------------------------------------------
public static void GetOO(OracleConnection conn)
{
OracleCommand cmd = new OracleCommand("UDT_TESTPROC", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
OracleParameter paramDaten = new OracleParameter("p_testobj", OracleDbType.Object, ParameterDirection.Output);
paramDaten.UdtTypeName = "USR.TESTOBJ";
cmd.Parameters.Add(paramDaten);
try { cmd.ExecuteNonQuery(); }
catch (Exception ex) //InvalidOperationException
{
Console.Out.WriteLine(ex.Message)
}
Console.In.ReadLine();
paramDaten.Value.ToString();
}
-----
Hope somebody can help me
thx in advance
faehne
|
|
|
|
|
hi there,
I am trying to make my service to insert to a database when it starts as follows :
protected override void OnStart(string[] args)<br />
{<br />
base.OnStart(args);<br />
string query;<br />
id += 1;<br />
<br />
SqlCommand comm;<br />
conn = new SqlConnection("my connection string");<br />
query = "insert into myTable values('" + id + "',lamya'" +"')";<br />
comm = new SqlCommand(query, conn);<br />
<br />
try<br />
{<br />
conn.Open();<br />
<br />
while (id >= 120)<br />
{<br />
comm.ExecuteScalar();<br />
query = "insert into myTable values('" + id + "',lamya'" + "')";<br />
comm = new SqlCommand(query, conn);<br />
id++; <br />
<br />
}<br />
conn.close();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
}<br />
<br />
<br />
}
after adding an installer and installing the service using the Installutil.exe
when I start the service from the services manager this msg shows up:
The ServiceOnTest service on your Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the performance Logs and the Alters service.
where ServiceOnTest is the service name ,
just to know if it matters: the startup type is automatically and it run for the local System
what should I do to make it work, I need it to insert to the database and more but first I need to know what wrong I did?
Urgent help is needed , please
Thanks
There is always something to learn
|
|
|
|
|
You either have a startup error or your onstart event takes to long to complete and gets shut down.
The onstart event is only for service initialization code. You either need to spawn a worker thread at the end of onstart or have it call an exe that will perform the task you need done.
|
|
|
|
|
That may all be fine; what does the main part of the service do?
Oh, wait... this will take a long time to finish, did you mean less than?
while (id >= 120)
{
comm.ExecuteScalar();
query = "insert into myTable values('" + id + "',lamya'" + "')";
comm = new SqlCommand(query, conn);
id++;
}
|
|
|
|
|
Thanks for replying
oh yes, exactly , I meant less than ,
after correcting every thing in the code , it started ,
but I need it to open a form, when I put a statement to open a form it refuses to start , (because of the line of opening the form)
thanks again,
There is always something to learn
|
|
|
|
|
A service does not have a "desktop" to show the form on, which is why im guessing it errors. There is a setting ("Allow service to interact with desktop" ) which is part of a windows service properties which when ticked allows a service to interact with the desktop.
I have never tried showing a form or anything from a service but this may help get you on your way.
Good luck
|
|
|
|
|
Thanks for replying
s_richie wrote: There is a setting ("Allow service to interact with desktop" ) which is part of a windows service properties which when ticked allows a service to interact with the desktop.
I have looked for it, but I did not find that property , can you give me a hint from where can I tick it to allow the interaction with the desktop, please?
There is always something to learn
|
|
|
|
|
Go to your Service in Administrative tools, right click it and select Properties. On to the Logon tab there is a check box there.
Services are not "meant" to interact with the desktop they are meant to be back ground items.
|
|
|
|
|