I am currently employed the first time in a C# .NET Frameworks project with Windows Forms. All the subjects are new to me. I am prototyping to find out how to solve different parts of the GUI so that they can first be specified (functional specification) and then implemented in the next six month or so.
One of the more involved dialogues has a coordinate system with a number of waveforms displayed. What I want to do is to change the vertical scaling (A, V, VA, W, etc.), if the user double-clicks on one of the waveforms.
To start the drawing of the waves, I use the following code:
/// Standard constructor
// Now, draw the waveforms, the surrounding box so that excessive waveforms going
// out of bounds are not visible, and the coordinates:
Pen pen = new Pen(Color.Gray);
SolidBrush brush = new SolidBrush(Color.White);
DrawCoordinates(pen, brush, usINCREMENT);
All the code worked fine till the problem arose that I am going to ask you.
To catch the mouse double-click event, I use the event handler by clicking on the control -a picture box- and selecting the events button under the properties in the Microsoft Visual Studio 2010 Premium - a button with a lightning symbol on it.
Here is the code for it:
private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs meas)
Interestingly, ClearBottom() & ClearLeft() used inside the pictureBox_MouseDoubleClic
k(...) method is also used in the SignalsForm class constructor indirectly (DrawSurroundingAreas(...)
). (SignalsForm is the waveform dialogue class where the problem occurs.)
/// Draws the white box around the coordinate system and the white
/// border to the left and bottom.
/// <param name="pen">
/// Pen needed to write text.
/// <param name="brush">
/// Solid brush needed to fill areas.
private void DrawSurroundingAreas(Pen pen, SolidBrush brush)
Rectangle rectangle = new Rectangle(m_usSPACE_RIGHT, 0,
pictureBox.Bounds.Right - m_usSPACE_RIGHT - 26, // 26??
pictureBox.Bounds.Bottom - m_usSPACE_BOTTOM);
pen.Color = Color.White;
// Draw the gray line around the waveforms:
pen.Color = Color.Gray;
pen.Width = 1;
rectangle.X -= 2;
rectangle.Y = -1;
rectangle.Height = pictureBox.Bounds.Bottom - m_usSPACE_BOTTOM + 2;
rectangle.Width += 1;
Here, the private methods ClearBottom() and ClearLeft() run properly.
/// Clears the bottom of the signal waveform screen.
private void ClearBottom()
Rectangle rectangle = new Rectangle(m_usSPACE_RIGHT,
pictureBox.Bounds.Bottom - m_usSPACE_BOTTOM,
pictureBox.Bounds.Right - m_usSPACE_RIGHT, m_usSPACE_BOTTOM);
SolidBrush brush = new SolidBrush(Color.Cyan);
/// Clears the left of the signal waveform screen.
private void ClearLeft()
Rectangle rectangle = new Rectangle(0, 0, 45, pictureBox.Bounds.Bottom);
SolidBrush brush = new SolidBrush(Color.Red); // White);
When calling the same two methods from the event handler method pictureBox_MouseDoubleClic
k(...), however, nothing happens at all.
How I tried to solve my problem
I thought that the problem may result somehow from using a Graphics member, called m_Graphics. So, I created another private method called ClearBottom2() that uses it's own Graphics object. It initialises it the same way as it is done in the constructor with a
Graphics g = Graphics.FromImage(picture
But this try for a workaround turned out to be of no use.
How can I clear the left and bottom of the PictureBox object, when a mouse double click occurs? Or in other words: What can be the reason why the small routines function very well when called from the constructor of the waveform class (SignalsForm), but not at all when called from the event handler method part of the same class?
Thank you for your help!