Jump to content
  • Advertisement
Sign in to follow this  
polisasimo

[.net] Drawing namespace ?

This topic is 4649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all I am fighting for air on this one. (I am using VB.net) The objective is draw a blue circle on a brown panel in my form. Seems harmless right? First and foremost thanks for the pateince with the question I have looked for information concerning the panel class on the MDN website, with no luck yet. My first problem is when in the design mode clicking on the panel sends me to the view code for an event. However the default event is:
Private Sub pnlA1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlA1.Paint
        
    End Sub


When I change the event to pnlA1.click i receive the following error: Method 'pnlA1_click' cannot handle Event 'Click' because they do not have the same signature. If this is the case how can I expect to draw the circle on the panel when the user clicks on the panel? Problem 2 I have tried to move on with hopes I could figure out this event problem later. When I try to draw something as simple as a line on the panel just to experiment I can't check it. Here is the code:
 Dim colCurrent As Color = Color.Blue 'declare a new color
        Dim pencurrent As New Pen(Color.Blue, 3) 'create an instance of the pen class
        e.Graphics.DrawLine(pencurrent, 0, 0, 100, 100)         'draw the line


I thought well if I can draw a line then maybe I will be able to draw a circle next, but it looks like without figureing out the click event I won't be able to see if this code even works on the panel. Also I assume I will need to use the drawing2d namespace to acheive this goal, but first things first :)

Share this post


Link to post
Share on other sites
Advertisement
If all you want to do is have 2D graphics in .NET, SdlDotNet might be the best way to go. It provides SDL bindings to .NET languages like C# and VB.NET.

The problem you're getting into is that it can't find pnlA1_click. You can fix that up by going into the Events panel and deleting pnlA1_click from the panel of events.

Share this post


Link to post
Share on other sites
Quote:
Method 'pnlA1_click' cannot handle Event 'Click' because they do not have the same signature.


Click signature (sorry, C# style):
void EventHandler(object sender, EventArgs e)

Paint signature:
void PaintHandler(object sender, PaintEventArgs pe)

So you have to change more than just the name.

Quote:
If this is the case how can I expect to draw the circle on the panel when the user clicks on the panel?

Check out on the internet how painting works in Windows. Otherwise you'll hit the #1 mistake by drawing beginners.
To sum it up: Do all the drawing in the Paint event. This will be called everytime Windows needs to repaint the window (e.g. if it was hidden by another window, minimized, out of screen, etc). If you don't, every painting you've done will disappear.

When the user click, save somewhere that you need to draw a circle. Then request a repainting from Windows using the Invalidate function. Then, in the paint event handler, do the actual drawing.

Hope it helps,
jods

Share this post


Link to post
Share on other sites
Quote:
Original post by Rob Loach
If all you want to do is have 2D graphics in .NET, SdlDotNet might be the best way to go. It provides SDL bindings to .NET languages like C# and VB.NET.

The problem you're getting into is that it can't find pnlA1_click. You can fix that up by going into the Events panel and deleting pnlA1_click from the panel of events.

wholey unecessary to include extra dependencies.


OP: the reason changing pnlA1_Paint to pnlA1_Click doesn't work is because the two methods take different sets of parameters.

this is the proper signature of a click handler

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub



I would personally handle the problem like this

Private signalDrawCircle As Boolean = False
Private brush As System.Drawing.Brush = New System.Drawing.SolidBrush(System.Drawing.Color.Blue)
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
signalDrawCircle = True
Label1.Invalidate()
End Sub
Private Sub label1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
If signalDrawCircle Then
e.Graphics.FillEllipse(brush, 0, 0, Label1.Width, Label1.Height)
End If
End Sub


oh man, that was enfuriating trying to figure out how to do that in VB. Wow. Do yourself a favor and switch to C#.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!