473,758 Members | 4,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2940
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_vbuButtonGrap hics As Graphics

Private Sub vbuButton_Paint (ByVal eventSender As System.Object, ByVal
eventArgs As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
m_vbuButtonGrap hics = Me.CreateGraphi cs()
DrawButton(m_vb uButtonGraphics )
'DrawButton(eve ntArgs.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_vbuButtonGrap hics As Graphics

Private Sub vbuButton_Paint (ByVal eventSender As System.Object, ByVal
eventArgs As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
m_vbuButtonGrap hics = Me.CreateGraphi cs()
DrawButton(m_vb uButtonGraphics )
'DrawButton(eve ntArgs.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
11535
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 that connects. This is so the individual user layers can be cleared. Each layer is painted on by the user it is assigned to, so the layer must respond to mouse events.
0
3428
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 areas to the left and right of the center line so that a person is better able to see when something is within 2 or 3 or 4 or 5 marks (degrees) of its neighbors. I can use a line and get it to rotate - that is no problem. The problem is drawing an...
2
2670
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 following specific parse error details and modify your source file appropriately. Parser Error Message: The base class includes the
0
2470
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 which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
41
4320
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 on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
7
2464
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 distinguish between ListViewItems. As long as no other application window (i.e. word or calculator, or ....) goes over my running form, ForeColor properties or each ListViewItem stays black or blue as intended.
0
2096
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 UserControl? (Script attached to, and executed by, a UserControl embedded server control can ‘see’ the UserControl through the root document architecture. How to get the script to execute and ‘see’ other server controls in the...
10
2428
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 my question. Once the UserControl is dropped onto the container page, how can I perform some action on the codebehind of the container page from the codebehind of the UserControl? For instance, suppose that the UserControl is dropped inside one...
11
9303
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, y1, x2, y2); }
0
9492
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10076
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...
0
9908
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8744
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7287
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
6564
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
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.