473,783 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DrawLine on panel on dynamic TabPage not working...help?

All

I am writing a C# WinForms application which is giving me some
problems.

The application consists of a form containing an empty Tab control to
which TabPages are added dynamically (at runtime). Each TabPage
contains a single Panel control. My intent is to draw a graph on that
Panel control dynamically, with the code capturing a point at each
update interval, then calling the Graphics.DrawLi ne method of the panel
to draw the line between the previous and "new" points.

At the moment, the application is written to add a single TabPage. The
form appears with the TabPage and its proper Panel control, but the
line does not appear. Every indication is that the code to draw the
line fires, but no line appears in the panel.

A debug-step through the code indicates each new point is computed
correctly; no exceptions are thrown, and the Pen used to draw the line
is of a contrasting color (Green against a white background). I've
tried invalidating the Panel, invalidating the parent TabControl,
refreshing the Panel, and a few other items, but nothing causes the
line to draw.

May I please ask for suggestions on what I am possibly overlooking? The
code that performs the line draw is as follows (plotHost is a reference
to a Control object used for the drawing surface); lastTranslatedP oint
is the "starting point" of the new line to be drawn, newPoint is the
"ending point." (The X and Y elements of lastTranslatedP oint are
initialized to -1 for the first pass because there is no "previous
point" from which to draw.) The variable xTick is simply the ticker for
the variable along the X axis.
public void AddNewValue(dec imal newValue)
{
try
{
int newYPlotValue = Convert.ToInt32 (
Decimal.Divide( newValue,maxPlo tValue*plotHost .Height);
Point newPoint = new Point(xTick,new YPlotValue);
if (lastTranslated Point.X!=-1 && lastTranslatedP oint.Y!=-1)
{
plotHost.Create Graphics().Draw Line(new Pen(new
SolidBrush(Colo r.Green),2),las tTranslatedPoin t,newPoint);
plotHost.Parent .Invalidate();
}
xTick+=4;
lastTranslatedP oint = newPoint;
}
catch(Exception e)
{
Console.WriteLi ne("Help!");
}
}

Many thanks in advance,
-intrepid

May 30 '06 #1
2 7164
in*********@hot mail.com wrote:
[painting using CreateGraphics]


Try painting in the control's Paint event, instead:
http://www.bobpowell.net/creategraphics.htm

Eq.
May 30 '06 #2
Paul,

Thanks for the reminder. I feel rather dumb for not having remembered
it, so I choose to blame the forgetfulness on too many intervening
years of web programming :)

Shifting the code to the Paint event solved the problem. DOH.

-intrepid
Paul E Collins wrote:
in*********@hot mail.com wrote:
[painting using CreateGraphics]


Try painting in the control's Paint event, instead:
http://www.bobpowell.net/creategraphics.htm

Eq.


Jun 2 '06 #3

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

Similar topics

2
5321
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted user controls. Worse I'm trying to add dynamic user controls from within a repeater loop (looping through attributes)... I bind to a function in the code behind and pass in the attribute. <asp:repeater id="rAttributes" Runat="server">
0
2129
by: redneon | last post by:
I'm trying to create a simple slide panel. Basically, what I've done is put a load of controls on a usercontrol and added this to a tabpage. The tabpage's height is 0 and when you move the mouse over the tab it uses a timer and increases the height of the tabpage by 1 every millisecond until the control reaches it's height. This way you get a slide effect. The problem is, when the control reaches a height of 1 it's time to draw the...
3
1887
by: Harry | last post by:
Hi, Can anyone help. I have a asp.net page (c#), with two panels, both of which have asp:textboxes on. When I press the first button, the second panel shows fine. When I press the button in the second panel, it triggers the script to send the form details by email.
2
3060
by: John | last post by:
I created a number of pictureboxes in a panel, and want to draw lines in those pictureboxes but I cannot. Please see the following code and make corrections. Thanks. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Panel1.AutoScroll = True Panel1.Width = 200 Panel1.Height = 200
7
4257
by: marfi95 | last post by:
Hi all, I have an app that contains a tab control with a tabpage on it. As part of the interface, the user keys in a field that basically identifies how many instances of these tabpages to have. So my basic question is how can I make copy of a tabpage dynamically so when the user says they want 3 occurrences, I add two new pages with all the same controls dynamically. The new pages should have exactly all the same controls as the...
12
9136
by: Adil Akram | last post by:
I'm using VS 2005, .net 2.0 for a desktop application (Window Form app). I can't set ZOrder of Panel control neither at design time by toolbar/menu command "Bring to Front"/"Sent to Back" nor at run time by calling BringToFront method of panel. And Panel control doesn't support SetTopLevel method etc. I tried this while Dock=Fill and Dock=None but its not working at all. Please tell me how can I change Panel's ZOrder specially at run...
3
22270
by: Jeff | last post by:
I done some looking on Google and could not come up with a way to dynamically create tab pages on a tab control. Does anyone have a link to any examples. Regards Jeff
0
1986
by: mustividyavtahi | last post by:
I am developing a windows application using c# in that i used tabcontrol in MDI form to display the child forms. that is working fine. but my problem is when i click a button in that tabpage (child form) it must open another form that also as tabpage which i am not getting . pls help me in this ...pls..... here is the code through which i am creating tabpages. public void settab(Form f2) { tabControl1.Visible = true;...
2
5717
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a javascript function that uses the ClientID of the dynamic controls to perform certain operations on the client-side. With each partial page post back, I dynamically recreate the javascript function using the ClientIDs of the newly added controls....
0
9480
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
10313
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
10147
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...
1
10081
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,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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...
0
6735
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
5378
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.