473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Painting when Button gets klicked

I want to paint some bars, as soon as a button get klicked.
My Paint Method has this signature:
Private Sub PaintChart(ByVal sender As Object, ByVal e As PaintEventArgs,
ByVal insolvent As Decimal, ByVal days30 As Decimal, ByVal days60 As
Decimal, ByVal days90 As Decimal, ByVal current As Decimal)

Means it needs to get a PaintEventArgs to work.

My Button Click Method has this signature:
Private Sub view_something_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles view_something.Click

In this method, I want to call my PaintChart method, because only then I
know all local parameters.
(okay, one solution would be to make all parameters global, but I doubt that
that was any good...)

PaintChart(sender, PaintEventArgs , insolvent, days30, days60, days90,
current)

Now the problem is, when I add the PaintEventArgs Event to my Click method,
then the signature doesnt fit anymore.

Have I got to do my own Handler, or how can that be solved???
(And how do I make one, if necessary)

Thanks,

Stefan
Nov 20 '05 #1
8 3292
Hi,

Create a graphics object for what you want to draw on in the click
event. In your PaintGraph procedure pass a graphics object instead of a
painteventargs. Here is a simple example on how draw bars when a user
clicks on a button.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim g As Graphics = PictureBox1.CreateGraphics

g.FillRectangle(Brushes.Red, 0, 0, 10, 50)
g.FillRectangle(Brushes.Blue, 10, 0, 10, 50)
End Sub

Ken
-------------------
"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
I want to paint some bars, as soon as a button get klicked.
My Paint Method has this signature:
Private Sub PaintChart(ByVal sender As Object, ByVal e As PaintEventArgs,
ByVal insolvent As Decimal, ByVal days30 As Decimal, ByVal days60 As
Decimal, ByVal days90 As Decimal, ByVal current As Decimal)

Means it needs to get a PaintEventArgs to work.

My Button Click Method has this signature:
Private Sub view_something_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles view_something.Click

In this method, I want to call my PaintChart method, because only then I
know all local parameters.
(okay, one solution would be to make all parameters global, but I doubt
that
that was any good...)

PaintChart(sender, PaintEventArgs , insolvent, days30, days60, days90,
current)

Now the problem is, when I add the PaintEventArgs Event to my Click
method,
then the signature doesnt fit anymore.

Have I got to do my own Handler, or how can that be solved???
(And how do I make one, if necessary)

Thanks,

Stefan

Nov 20 '05 #2
What is PictureBox1.CreateGraphics?

And, when I created this Graphic, how could I forward it to my method again?
Cause the paint method that reacts on the PaintEventArgs can't have extra
arguments,
because otherwise the necessary signature for this event doesn't fit
anymore.

Sorry, Iam really confused by this stuff!

Maybe I should show you, what I want to do:

OnClick {

CalculateCoordinates()
DrawBars(Coordinates)

}
CalculateCoordinates{
.........
.........
}

DrawBars{
.........
.........
}
Thx,

Stefan
Nov 20 '05 #3
Hi,

The graphics object is the class the handles drawing on a form or
control. Try something like this.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim g As Graphics = PictureBox1.CreateGraphics
PaintChart(g, 0, 0, 0, 0, 0)
End Sub

Private Sub PaintChart(ByVal g As Graphics, ByVal insolvent As Decimal,
ByVal days30 As Decimal, ByVal days60 As Decimal, ByVal days90 As Decimal,
ByVal current As Decimal)
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)
g.FillRectangle(Brushes.Red, 0, 0, 10, 50)
g.FillRectangle(Brushes.Blue, 10, 0, 10, 50)

End Sub

Ken
---------------------------
"Stefan Richter" <sp**@spammenot.com> wrote in message
news:c7***********@otis.netspace.net.au...
What is PictureBox1.CreateGraphics?

And, when I created this Graphic, how could I forward it to my method
again?
Cause the paint method that reacts on the PaintEventArgs can't have extra
arguments,
because otherwise the necessary signature for this event doesn't fit
anymore.

Sorry, Iam really confused by this stuff!

Maybe I should show you, what I want to do:

OnClick {

CalculateCoordinates()
DrawBars(Coordinates)

}
CalculateCoordinates{
........
........
}

DrawBars{
........
........
}
Thx,

Stefan

Nov 20 '05 #4
"Stefan Richter" <sp**@spammenot.com> schrieb
What is PictureBox1.CreateGraphics?
It is a call of the CreateGraphics method of the Picturebox. Press <F1> for
more.
And, when I created this Graphic, how could I forward it to my method
again? Cause the paint method that reacts on the PaintEventArgs can't
have extra arguments,
because otherwise the necessary signature for this event doesn't
fit anymore.


Write a procedure. The procedure does the painting. One argument of the
procedure is a Graphics object. Call the procedure in the paint event. Pass
e.graphics to the procedure. In your click handler, call the proecedure,
too. As you don't have a graphics object there, you have to create it by
calling Creategraphics. Similar to Ken's answer:

Dim g As Graphics

g = PictureBox1.CreateGraphics
try
YourPaintingProcedure(g)
finally
g.dispose
end try

sub YourPaintingProcedure(byval g as graphics)
'Paint on g here
end sub

Instead of calling the procedure in the click event, you can simply call
Picturebox1.invalidate. This invalidates the picturebox' content. See
http://msdn.microsoft.com/library/en...tdraw_7zn2.asp
and the following topics.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Sorry, but that doesn't work.
I guess it's because MyBase.Paint does not repaint the Object over and over
again.

Dim PictureBox1 As New System.Windows.Forms.PictureBox

I tried:

Private Sub view_crs_mth_btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles view_crs_mth_btn.Click

.......

....

Dim g As Graphics = PictureBox1.CreateGraphics

g.FillRectangle(Brushes.Red, 0, 0, 10, 50)

g.FillRectangle(Brushes.Blue, 10, 0, 10, 50)

..............

End Sub
Nov 20 '05 #6
Okay, so you want me to write a paint procedure.
-----------
Private Sub PaintChart(ByVal e As Graphics, ByVal value1 As Integer, ByVal
value2 As Integer )

e.FillRectangle(Brushes.White, 530, value1 , 35, 150)
e.FillRectangle(Brushes.Lime, 600, value2, 35, 75)

End Sub

-------------
Then you want me to write a paint event:
Private Sub PaintChart2(ByVal sender As Object, ByVal e As PaintEventArgs)
Handles MyBase.Paint

Dim g As Graphics = e.Graphics

PaintChart(g, 0, 0)

End Sub

------------

How can I know value1 and value2 in the paint event????

---------

Private Sub view_crs_mth_btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles view_crs_mth_btn.Click

Dim value1 As Integer

Dim value2 as Integer

.....

Dim g As Graphics

Dim PictureBox1 As New System.Windows.Forms.PictureBox

g = PictureBox1.CreateGraphics

PaintChart(g, value1, value2)

-----------
So value1 and value2 have to be global for the whole class then????
And if so, how can I hide the Graphics again or better how can I stop the
Paint
method to try to paint it again???

thx,

Stefan
Nov 20 '05 #7
Doesn't seem to work, as a method that handles MyBase.Paint is missing.

Cheers,

Stefan
Nov 20 '05 #8
"Stefan Richter" <sp**@spammenot.com> schrieb
Okay, so you want me to write a paint procedure.
-----------
Private Sub PaintChart(ByVal e As Graphics, ByVal value1 As Integer,
ByVal value2 As Integer )

e.FillRectangle(Brushes.White, 530, value1 , 35, 150)
e.FillRectangle(Brushes.Lime, 600, value2, 35, 75)

End Sub

-------------
Then you want me to write a paint event:
Private Sub PaintChart2(ByVal sender As Object, ByVal e As
PaintEventArgs) Handles MyBase.Paint

Dim g As Graphics = e.Graphics

PaintChart(g, 0, 0)

End Sub

------------

How can I know value1 and value2 in the paint event????

---------

Private Sub view_crs_mth_btn_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles view_crs_mth_btn.Click

Dim value1 As Integer

Dim value2 as Integer

....

Dim g As Graphics

Dim PictureBox1 As New System.Windows.Forms.PictureBox

g = PictureBox1.CreateGraphics

PaintChart(g, value1, value2)

-----------
So value1 and value2 have to be global for the whole class
then????
Yes
And if so, how can I hide the Graphics again or better how
can I stop the Paint
method to try to paint it again???


Why stop it? The Paint event is only raised if it is required.
In general, you must remember what you want to display in the control.
Whenever the data influencing the painting changes, or whenever Windows
wants you to repaint, you must paint again.
--
Armin

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill K | last post by:
I am developing a winforms project in vb.net. I have several forms that have a number of controls, grids, etc. When I load these as MDI child forms, they load slowly AND they paint/repaint on the...
1
by: guy | last post by:
Is it possible to select all text in a asp text box when it gets focus? How?
5
by: mail2kondeti | last post by:
Hi Here I need know small clarification. I did this long time back. If I want to show the cursor in the first field when the page gets loaded, how we have to do? Ex. if you goto...
1
by: thewickedman | last post by:
Hi, I try to open new OpenOffice document (writer), But I am getting the exception FRM 40735:WHEN-BUTTON-PRESSED Trigger Raised unhandled Exception ORA - 305500 Please help me to resolve...
2
by: jayasabari | last post by:
Hai, When button is clicked, then i have to prevent the execution of one function in page load. can you give any suggestion please. With Regards, K.Jayasabari
9
by: ghjk | last post by:
change the background image when Button Click ====================================== I' developing site with php and postgres. It has menus list in the left side. and all are images(jpg) EX:Add...
3
by: sarangrao | last post by:
I have put 4 radio buttons on web page.Each and every radio button gets selected.Why is it so?Even if Iam placing these radio buttons in panel or place holder.Iam able to check every radio button.
3
dsatino
by: dsatino | last post by:
Does anyone know how to accomplish this? I have many processes that constantly update the screen. Sometimes it's custom progress bars, sometimes it's data, it doesn't really matter. My problem is...
2
by: sohil | last post by:
How to open a file that contains some other extension like(.mxd) when button is click
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.