473,387 Members | 1,536 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,387 software developers and data experts.

Redrawing graphics in userControl - Button

Hi all,

I've created a Custom button control and i'm drawing the graphics for
the button when the paint event is fired. I used Invalidate method to
redraw the graphics in events like mousemove, click etc.

My problem is as follows: I created a test application to test the
created custom button control. I had two buttons on the form. When i
click on one button 1 a message box is showed. This message box covers
one part of the other button 2 in the form. When i dismiss the message
box in such a way that the mouse is not over button 2, a part of the
text in caption of button2 disappears. But what ever may be the case,
button 1 appears properly as i have called invalidate during the click
event for that button1.

I understand that some event would be fired in button2 when i dismiss
the message box, during which i need to call Invalidate? Can some one
tell me where to call Invalidate to repaint the graphics in the
button2.

Thanks in advance,
Sugan

Jul 10 '06 #1
4 2917
You only have to invalidate the control when you have made something
that changes the apperance of the control. Normal drawing, e.g. when
windows move over and away from the control and such, is handled
automatically.

If the control isn't redrawn correctly when when it has been covered and
reappear, there is something wrong with your code that handles the Paint
event.

Sugan wrote:
Hi all,

I've created a Custom button control and i'm drawing the graphics for
the button when the paint event is fired. I used Invalidate method to
redraw the graphics in events like mousemove, click etc.

My problem is as follows: I created a test application to test the
created custom button control. I had two buttons on the form. When i
click on one button 1 a message box is showed. This message box covers
one part of the other button 2 in the form. When i dismiss the message
box in such a way that the mouse is not over button 2, a part of the
text in caption of button2 disappears. But what ever may be the case,
button 1 appears properly as i have called invalidate during the click
event for that button1.

I understand that some event would be fired in button2 when i dismiss
the message box, during which i need to call Invalidate? Can some one
tell me where to call Invalidate to repaint the graphics in the
button2.

Thanks in advance,
Sugan
Jul 10 '06 #2
The exact problem is when i click on button1, it throws a message box
which covers part of button2. When the message box is dismissed, the
area covered by the message box alone is refreshed( graphics in this
area is displayed as desired). The uncovered area of the button2 loses
the part of the caption( loses the previously drawn graphics). However
when i move the mouse over the button2, i'm invalidating the control
and hence the whole graphics gets redrawn perfectly as i desire.

I want the whole graphics to be redrawn when the message box is
dismissed. Pls note that button1 has the when i click on it. Then
message box is thrown that covers button2. when message box is
dismissed, i want to know the event that would be fired to refresh the
graphics in button2.

Thanks,
Sugan.
Göran Andersson wrote:
You only have to invalidate the control when you have made something
that changes the apperance of the control. Normal drawing, e.g. when
windows move over and away from the control and such, is handled
automatically.

If the control isn't redrawn correctly when when it has been covered and
reappear, there is something wrong with your code that handles the Paint
event.
Jul 10 '06 #3
Hi,

I found the answer for this issue myself.

What i did is, instead of using the eventArgs argument to draw graphics
in the UserControl, i declared a variable and assigned the graphics of
the button which helps to retain the graphics of the button after
dismissing the message box. Any way thanks and here is the code.

visual basic code:

Dim m_vbuButtonGraphics As Graphics

Private Sub vbuButton_Paint(ByVal eventSender As System.Object, ByVal
eventArgs As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
m_vbuButtonGraphics = Me.CreateGraphics()
DrawButton(m_vbuButtonGraphics)
'DrawButton(eventArgs.Graphics)
End Sub

-Sugan
_________

Jul 10 '06 #4
You have forgotten to call Dispose on the graphics object you create.

The graphics object that you get in the event arguments is what you are
supposed to use to redraw the control. If you don't, you risk to draw
more than you are supposed to, like if the control is partly covered by
another window, you would draw the control on top of that window.

What does the DrawButton method do?
Sugan wrote:
Hi,

I found the answer for this issue myself.

What i did is, instead of using the eventArgs argument to draw graphics
in the UserControl, i declared a variable and assigned the graphics of
the button which helps to retain the graphics of the button after
dismissing the message box. Any way thanks and here is the code.

visual basic code:

Dim m_vbuButtonGraphics As Graphics

Private Sub vbuButton_Paint(ByVal eventSender As System.Object, ByVal
eventArgs As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
m_vbuButtonGraphics = Me.CreateGraphics()
DrawButton(m_vbuButtonGraphics)
'DrawButton(eventArgs.Graphics)
End Sub

-Sugan
_________
Jul 11 '06 #5

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

Similar topics

5
by: C. Alexander | last post by:
I'm trying to create a multi-user interactive whiteboard that has the ability to load a 'background' image to draw ontop of. The client/server needs to load a transparent layer for each user...
0
by: Otie | last post by:
I have a circle that displays information in 1-degree increments - there are 90 such increments that comprise the circle. I need a pointer within the circle that rotates. The pointer must include...
2
by: bill yeager | last post by:
When trying to run my web project, I get the following error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
7
by: Dino Buljubasic | last post by:
Hi, I am using C# 2.0 (VS2005) to build my user control that contains a number of dynamically loaded ListViews. ListViewItems have their ForeColor properties set to either black or blue to...
0
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
11
by: cty0000 | last post by:
I have some quiestion... I want to draw line,point,rectangles and etc... on the from So I code like this.. public update() { g = this.CreateGraphics(); g.FillRectangle(Brushes.White, x1,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.