|
I have been told and told and told (correctly) that I MUST do all my drawing in the Paint handler. That being said here is my simple problem.
1. I have a class:
MyClass
{
//let's forget Set/Get and make public....
public int x;
public int y;
}
2. I have the Paint handler:
protected override OnPaint(..,..)
{
}
Here's my problem?
I want to pass the x, and y coordinates as the x2, y2 coordinates of the args in a g.DrawLine overload inside some function as in--(assume x1, y1, both have a value of 20--
"return type" DrawFunc("some args or void?")
{
g.DrawLine(pen, 20, 20, "x", "y")
}
Is this the right way to do this?
Does "g.DrawLine(...) need to be INSIDE the paint handler?
Also I will want to draw more lines with different values of x, and y.
I know how to Set/Get them. I want to know the correct way to draw them in the Paint handler from a function call... please help thanks
|
|
|
|
|
You mean something like this?
protected override void OnPaint(PaintEventArgs pea) {
MyDrawLine(pea.Graphics, 89, 76);
MyDrawLine(pea.Graphics, 32, 45);
}
private void MyDrawLine(Graphics g, int x, int y) {
g.DrawLine(somePen, 20, 20, x, y);
}
For sure all painting should be done in the OnPaint-method but you can call helping drawing functions from there and just pass the Graphics object araound.
|
|
|
|
|
Yes-- something like that.... many thanks!
One other question, I forgot to add in my post. I need a button1 event to fire when the user wants the line drawn. Does "MyLineDraw(...)" go inside the button1 braces??
//i.e
button1_Click
{
// Want it do draw the first line.....
}
|
|
|
|
|
No. You'd call this.Invalidate() which in turn will call OnPaint()
|
|
|
|
|
Thanks for your answer. I guess I need to define it a bit more...
Lets say I have button1 that draws line A and button 2 that draws line B
How does the button get linked to the method that draws say, lineA and not lineB or vice-versa... - thanks again
|
|
|
|
|
Store somewhere what lines should be drawn. In the event that handles each button you update the information on which lines should be drawn, then you invalidate the area that has your paint event, so that the paint event will be called to redraw the area, thus redrawing the lines.
The reason that you have to store somewhere what lines should be drawn, is that the paint event will be called everytime the area needs redrawing. For an example, if you move some other window across your window, the paint event will be called to redraw the area when it appears again.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks very much for you reply but I don't quite understand...
DrawLineA(arg, arg, arg)
{
g.DrawLine(Pen, x1, y1, x2, y2)
}
DrawLineB(arg, arg, arg)
{
g.DrawLine(Pen, x1, y1, x2, y2)
}
ButtonA_Click(sender, e)
{
//put line A on Form
//Invalidate()??
}
ButtonA_Click(sender, e)
{
//put line B on Form
//Invalidate()??
}
protected override void OnPaint(Paint Event Args pe)
{
//??
//Invalidate()??
}
|
|
|
|
|
SkunkedWorks wrote:
ButtonA_Click(sender, e)
{
//put line A on Form
//Invalidate()??
}
No. You don't put the line on the Form.
You update the state information that your application has to track to know what lines the Paint event needs to draw. Then you invalidate the control and it uses the state information to repaint itself using your OnPaint drawing code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
this is a basic object oriented design issue. the whole purpose to having all the drawing in the overrided onPaint is because you want to not have to worry about calling/optimizing the drawing processs. That is, the object is responisble for drawing itself. Any code using your class won't have to know the specific rules for drawing your object, thus achieving loose coupling... well enugh said, in practice what you want to do is:
MyClass{
private int _x = 0;
private int _y = 0;
private bool drawLineA = false;
private bool drawLineB = false;
public void setInitialXY(int x,int y)
{
_x = x;
_y = y;
}
private void MyDrawLine(Graphics pg, int x,int y)
{
pg.DrawLine(_x,_y, x, y);
}
protected override void OnPaint(PaintEventArgs pe)
{
if(drawLineA)
MyDrawLine(pe.Graphics, 87, 67);
if(drawLineB)
MyDrawLine(pe.Graphics, 55, 94);
}
public void ToggleLineA()
{
drawLineA = !drawLineA;
this.Invalidate();
}
public void ToggleLineB()
{
drawLineB = !drawLineB;
this.Invalidate();
}
}
I hope this answers your question and explains concept...
-- modified at 15:11 Friday 23rd September, 2005
|
|
|
|
|
More along the line of:
LineInfo a, b;<br />
<br />
ButtonA_Click(sender, e)<br />
{<br />
a = new LineInfo(x1, y1, x2, y2);<br />
Invalidate();<br />
}<br />
<br />
ButtonB_Click(sender, e)<br />
{<br />
b = new LineInfo(x1, y1, x2, y2);<br />
Invalidate();<br />
}<br />
<br />
protected override void OnPaint(Paint Event Args pe)<br />
{<br />
if (a != null) a.Draw(g, pen);<br />
if (b != null) b.Draw(g, pen);<br />
}
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
To declare :
Excel.Application oXL = new Excel.Application();
what directives I have to have. Debuger complains that there is no such type or namespace as Excel.
Thank you
|
|
|
|
|
You need to add a reference to the Microsoft Excel x.x Library (COM)
|
|
|
|
|
I'm just about finished with a setup and deployment project, but one thing I'd like to change is this: when I go to install the newest version, it tells me that this program is already installed, so I have to go to 'Add/Remove Programs' to remove it first. I turned on the property 'remove previous versions', but it doesn't seem to work. Isn't there a way I can have the new installation remove the old one on its own?
My articles
BlackDice
|
|
|
|
|
You need to change the version number for the installer and change the product code for it to work.
|
|
|
|
|
DOH! I hate being an idiot sometimes. Thanks!!
My articles
BlackDice
|
|
|
|
|
I drag a "HTML control" ---"file field" and then I change it to run at server
when My Operating System is windows2000 server, I can simple set "write" security to
"everyone" ,and then I can upload the client file to server directory.
the code is below:
--------------------------------------------
private void btnUpLoad_Click(object sender, System.EventArgs e)
{
String fullfileName=this.File1.PostedFile.FileName;
String fileName=fullfileName.Substring(fullfileName.LastIndexOf("\\")+1);
this.File1.PostedFile.SaveAs(Server.MapPath("up")+"\\"+fileName);
}
--------------------------------------------
My question is: when I use windows XP, it doesn't work,when debug it,I find a error:
Access to the path "C:\Inetpub\wwwroot\uploadFile\up\tech.pdf" is denied.
So, I want to know Is there any common technology to do upload file to server
no matter what OS it is (for: windows2000 or windows XP,it can run correct?)
Can you show me how to do it??
Thank you very much!
shanzy
|
|
|
|
|
Does the ASPNET account, or whatever account your site is running under, have write permissions to the folder you're trying to put this file in? By default, it doesn't.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How do I determine the Type of the object that is calling a particular method from within the method?
|
|
|
|
|
AFAIK, you can't. From an OOP perspective, your method shouldn't even care what's or who is calling it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Its purely for logging purposes. I'm using log4net and planning to have a central logger. I'll have a static method for logging. It'll be good if the calling object's type can be retrieved automatically. Of course I can pass the type as a parameter to the method. But just wondering if it's possible to do it automatically...
|
|
|
|
|
Contrary to what Dave said, finding the Type is quite easy, getting an object reference is another story.
Look at the StackTrace class, a couple a frames down u will see the current method and the next frame will be your calling method. From the StackFrame get the MethodBase , and get the DeclaringType property for the calling type.
HTH
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
Cool. Come to think of it, I think I saw this question last week somewhere. The StackTrace won't give to the passed in params though.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Awesome. Thanks leppie. I just wanted the Type.
|
|
|
|
|
Hello,
I want to display a report using Crystal Reports. How can I format the report before displaying it in crystalReportViewer; something like page width, number of columns, etc...
Thank you
|
|
|
|
|
Members,
I am interested in maintaining my tab order on a web page. I have a very simple page with 2 dialog boxes & 2 dropdownlist boxes.
Field1 DropDownList1
Field2 DropDownList2
I have the tab order set from left to right from the top down. So, you cursor move from Field1 to DropDownList1, to Field2 and finally to DropDownList2.
However, when the selectedindexchanged event fires, I no longer maintain my focus and leave DropDownList1 and land in Field2.
Where does the cursor go (besides the address bar of the current webpage) and how to I get the focus to move to the next field in order?
Any thoughts would be appreciated.
Thank you.
|
|
|
|
|