473,801 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByVa l 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.EventArg s) 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(send er, 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 3324
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Dim g As Graphics = PictureBox1.Cre ateGraphics

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.netspa ce.net.au...
I want to paint some bars, as soon as a button get klicked.
My Paint Method has this signature:
Private Sub PaintChart(ByVa l 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.EventArg s) 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(send er, 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.Cre ateGraphics?

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 {

CalculateCoordi nates()
DrawBars(Coordi nates)

}
CalculateCoordi nates{
.........
.........
}

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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Dim g As Graphics = PictureBox1.Cre ateGraphics
PaintChart(g, 0, 0, 0, 0, 0)
End Sub

Private Sub PaintChart(ByVa l 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(B rushes.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.netspa ce.net.au...
What is PictureBox1.Cre ateGraphics?

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 {

CalculateCoordi nates()
DrawBars(Coordi nates)

}
CalculateCoordi nates{
........
........
}

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

Stefan

Nov 20 '05 #4
"Stefan Richter" <sp**@spammenot .com> schrieb
What is PictureBox1.Cre ateGraphics?
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.Cre ateGraphics
try
YourPaintingPro cedure(g)
finally
g.dispose
end try

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

Instead of calling the procedure in the click event, you can simply call
Picturebox1.inv alidate. 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.PictureBo x

I tried:

Private Sub view_crs_mth_bt n_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles view_crs_mth_bt n.Click

.......

....

Dim g As Graphics = PictureBox1.Cre ateGraphics

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(ByVa l 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(ByV al 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_bt n_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles view_crs_mth_bt n.Click

Dim value1 As Integer

Dim value2 as Integer

.....

Dim g As Graphics

Dim PictureBox1 As New System.Windows. Forms.PictureBo x

g = PictureBox1.Cre ateGraphics

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(ByVa l 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(ByV al 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_bt n_Click(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles view_crs_mth_bt n.Click

Dim value1 As Integer

Dim value2 as Integer

....

Dim g As Graphics

Dim PictureBox1 As New System.Windows. Forms.PictureBo x

g = PictureBox1.Cre ateGraphics

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
2240
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 screen, and it makes a sloppy presentation. I am unhappy with it, and obviously the client says that it is unacceptable. How can I make a nice, crisp form/screen opening? Thanks so much for you help.
1
6061
by: guy | last post by:
Is it possible to select all text in a asp text box when it gets focus? How?
5
7606
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 www.mail.yahoo.com , cursor shows on user id I know that we need to call onload function in BODY tag. It worked too for text field.
1
17789
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 this exception. my code is as follows in when-button-pressed trigger:
2
1496
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
26031
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 User, Edit User, Remove user(all arebuttons) I have another set of images with different color. Those will display only after the mouse click. How can I do this? How can change the image(button) when clicked? Please help me
3
1493
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
1895
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 this: If the user switches the focus of their PC to another application while the access process is running, the screen painting stops. To the user, it seems as if the code has frozen, but it hasn't. Is there anyway to keep the screen...
2
2265
by: sohil | last post by:
How to open a file that contains some other extension like(.mxd) when button is click
0
9556
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10516
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10262
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7589
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6829
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.