|
Please don't double post.
---
b { font-weight: normal; }
|
|
|
|
|
Is it possible to add a placeholder to a datatable?
If so, how?
Thanks.
|
|
|
|
|
Can you give an example of what you are trying to do?
|
|
|
|
|
I am trying to make a class library that contains some drawing routines for example:
public GraphicsPath DrawRoundRect( Pen p, float X, float Y, float width, float height, float radius)
{
GraphicsPath gp=new GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius*2), Y);
gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));
gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);
gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);
gp.AddLine(X, Y + height - (radius*2), X, Y + radius);
gp.AddArc(X, Y, radius*2, radius*2, 180, 90);
gp.CloseFigure();
return gp;
}
The compiler doesn's know what GraphicsPath is so you add
using System.Drawing.Drawing2D;
Then the compiler says can resolve symbol Drawing.
Of course all works fine if you are in the applications main form.
How do I get around this problem?
|
|
|
|
|
Hello
Check, that you have added System.Drawing to your project references. Right-click on References folder of your project and select "Add Reference".
With best regards,
Andrew
|
|
|
|
|
I had added System.Drawing but being new to C# I had not added a reference.
Thank you very much.
|
|
|
|
|
I have a WinForm that contains a RectF. I have methods to draw inside the RectF as in, DrawLine(...).
I also have a bool flag in a try/catch block that throws up a MessageBox if the line params (they come from TextBoxes linked to Button events) are false.
Now here's the problem....
When I click the "OK" or the "x" on the MessageBox, the line(s) gets erased partially, based on where the MessageBox overlapped the line.
The RectF, the graph axes and labels all remain. What's up w/ that??
thanks....
Here's some of the code.....
////////////////////////////////////////////////////////////////////////
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DrawGraphRectF(e.Graphics);
DrawXYAxes(e.Graphics);
DrawGraphXandYTicks(e.Graphics);
}
//Background "reference" rectangle
void DrawGraphRectF(Graphics g)
{
Pen rectPen = new Pen(Color.BlueViolet);
g.DrawRectangle(rectPen, xIndent, yIndent, graphRect.Width, graphRect.Height);
g.FillRectangle(new SolidBrush(Color.Snow), xIndent + 1, yIndent + 1, graphRect.Width - 1, graphRect.Height - 1);
rectPen.Dispose();
}
//Draw x and y axes.
void DrawXYAxes(Graphics g)
{
Pen axisPen = new Pen(new SolidBrush(Color.BlueViolet), 1);
g.DrawLine(axisPen, xIndent, yIndent + graphRect.Height/2, xIndent + graphRect.Width, yIndent + graphRect.Height/2);
g.DrawLine(axisPen, xIndent + graphRect.Width/2, yIndent, xIndent + graphRect.Width/2, yIndent + graphRect.Height);
axisPen.Dispose();
}
//Draw tick marks on the axes.
void DrawGraphXandYTicks(Graphics g)
{
Pen tickPen = new Pen(new SolidBrush(Color.Black), 1);
//Draw x-axis ticks and label graph.
float fxAxis = -8.0f;
float fyAxis = 8.0f;
PointF xtickPoint = new PointF(xIndent, yIndent + graphRect.Height/2);
PointF ytickPoint = new PointF(xIndent + graphRect.Width/2, yIndent);
Font labelFont = new Font("Courier",6);
SolidBrush labelBrush = new SolidBrush(Color.Black);
StringFormat strFmt = new StringFormat();
//Draw x axis ticks and float labels.
for(float fx = 2 * xtickPoint.X; fx <= graphRect.Width; fx += xtickPoint.X)
{
//string measureString = f.ToString("f1");
//float measureLength = measureString.Length;
if(fxAxis == 0.0f)
{
fxAxis += 1.0f;
fx += xtickPoint.X;
}
g.DrawLine(tickPen, fx, xtickPoint.Y - 2, fx, xtickPoint.Y + 2);
g.DrawString((fxAxis > 0? "+" : "" ) + fxAxis.ToString("f1"), labelFont, labelBrush, fx - 7, xtickPoint.Y + 7);
fxAxis++;
}
//Draw y-axis ticks and float labels.
for(float fy = 2 * ytickPoint.Y; fy <= graphRect.Height; fy += ytickPoint.Y)
{
if(fyAxis == 0.0f)
{
fyAxis -= 1.0f;
fy += ytickPoint.Y;
}
g.DrawLine(tickPen, ytickPoint.X - 2, fy, xtickPoint.Y + 2, fy);
g.DrawString((fyAxis > 0? "+" : "") + fyAxis.ToString("f1"), labelFont, labelBrush, ytickPoint.X + 5, fy - 3);
fyAxis--;
}
tickPen.Dispose();
}
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g,cmplxPen, mValReal, mValComplex);
bShowValue = false;
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
private void complexB_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Green, 4);
//
try
{
mValReal = Convert.ToDouble(this.textComplexBReal.Text);
mValComplex = Convert.ToDouble(this.textComplexBComplex.Text);
DrawComplexNumber(g, cmplxPen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex B Number", "Error!");
}
}
void DrawComplexNumber(Graphics g, Pen cmplxPen, double re_, double im_)
{
g.DrawLine(cmplxPen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
private void button1_Click(object sender, System.EventArgs e)
{
Invalidate();
}
}
}
|
|
|
|
|
This is happening because you're doing some drawing from a button click event. Thereis no code in your Paint event to redraw these objects when the form is told to repaint itself.
Your app must keep a "state" that contains everything the Paint event needs to know to redraw everything at any time, not just wehen you click a button on your form.
Think about this. You have a button on your form that when you click, you add a random line to the form. Now, if you drew the line from inside the Click event of the button, the line will only be drawn once, ever! If the form is overlayed by another app or form and then moved out of the way, the Paint event doesn't know anything about the line that was drawn, so it can't be redrawn when the form is repainted.
But, if you add the endpoints of the line to an array and your Paint event is coding to redraw the lines using the data in the array, there's no problem. If the lines get overlapped by another app or form, then the app or form is moved out of the way, the Paint event now knows how to redraw the lines.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've asked this question a couple of time, but never seem to get any replies. I'm not sure if it's just because it's impossible to do or what, but I'm going to give it one more try.
Is there anyway in C# to be notified of changes in the time (i.e. the clock in the system tray). For example if I want to know when the time changes from 4:00 to 5:00 or when the minute changes. Is this possible at all?
Any bit of help will be very appreciated.
Thanks.
- Aaron
|
|
|
|
|
To be notified when time changed
add using Microsoft.Win32; use SystemEvents to subscribe to TimeChanged event some thing like
SystemEvents.TimeChanged +=new EventHandler(SystemEvents_TimeChanged);
and in your event handler
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
MessageBox.Show("Time Changed");
}
Know run your program and change your time message box Will be displayed
MCAD
|
|
|
|
|
This event fires when the user changes the system time, not when the hour changes or the minutes changes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes I Know that he said
Is there anyway in C# to be notified of changes in the time (i.e. the clock in the system tray
So i gave him this answer
MCAD
-- modified at 13:30 Sunday 11th September, 2005
|
|
|
|
|
He posted the question a couple times before, but just worded it a bit differently. I didn't mean to smack you for the wrong answer. Sorry...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There is no event like this.
You'll have to create your own component to minitor the current time and fire events of your own when the hour and/or minute changes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If you mean when the user changes the time then Mohamad gave you the correct answer.
If you want a timer, then you might be interested in this: http://www.codeproject.com/dotnet/ABTransClockArticle.asp[^]
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
The article seems to be what I'm looking for.
Thanks for the help.
- Aaron
|
|
|
|
|
Um... This may come as a shock to you, but the time is changing constantly. It never stops changing. Even when you turn off the computer.
However, if you want notifications of minute and hour changes, it would be quite simple to use a timer that in turn keeps track of those transitions and calls OnMinute and OnHour events.
Matt Gerrans
|
|
|
|
|
Hi all
I'm building a treeview which is populated programatically using a recursive function. This function assigns a contextmenustrip to each node as it's built. What I need to know is how to identify the node in the treeview that was r-clicked to show the contextmenustrip.
Eg.
Root
|_Child1
|_Child2
|_Grandchild
Child1 might be the selected node but I'm going to r-click Grandchild, displaying the contextmenu. If I have an "Add Node" on the contextmenustrip, I want to be able to identify that I'm adding the node to Grandchild.
Thanks in advance
MrR_
Nothing is foolproof to the talented fool.
-- modified at 18:49 Saturday 10th September, 2005
|
|
|
|
|
|
Select the node when write click it some thing like
private void treeView1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeViewHitTestInfo tvt = treeView1.HitTest(e.X, e.Y);
treeView1.SelectedNode = tvt.Node;
}
}
now if you want to add sub item to selected node
private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
{
treeView1.SelectedNode.Nodes.Add("Add Test Node");
}
MCAD
-- modified at 19:51 Saturday 10th September, 2005
MCAD
-- modified at 19:58 Saturday 10th September, 2005
|
|
|
|
|
Thanks for that. I wasn't sure whether I needed to change focus to the node I was r-clicking or whether there was a way of identifying the node from the context menu. All working now.
Nothing is foolproof to the talented fool.
|
|
|
|
|
you do not have change the selected node this just example you can save selected node and restore it after you finish your work Or you can modifey previous code as the following
in the form level
private TreeNode activeNode;
private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (activeNode != null)
{
activeNode.Nodes.Add("Add Test Node");
MessageBox.Show(treeView1.SelectedNode.Text);
}
private void treeView1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeViewHitTestInfo tvt = treeView1.HitTest(e.X, e.Y);
activeNode = tvt.Node;
}
}
I hope this help
MCAD
-- modified at 13:58 Sunday 11th September, 2005
|
|
|
|
|
Meny people have told me that ALL drawing should be done in the Paint handler.
I need to pass the Pen object from my function into the Paint handler but I
can't seem to figure out how to get it to accept the 2nd arg(cmplxPen).
Please advise -- thanks...
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DrawGraphRectF(e.Graphics);
DrawXYAxes(e.Graphics);
DrawGraphXandYTicks(e.Graphics);
if(bShowValue)
{
DrawComplexNumber(this.CreateGraphics(),this./*"WHAT GOES HERE?"*/, mValReal, mValComplex);
}
//
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
//DrawComplexNumber(g,cmplxPen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
|
|
|
|
|
void DrawComplexNumber(Graphics g, Pen cmplxPen, double re_, double im_)
{
g.DrawLine(cmplxPen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
|
|
|
|
|
Anonymous wrote:
if(bShowValue)
{
DrawComplexNumber(this.CreateGraphics(),this./*"WHAT GOES HERE?"*/, mValReal, mValComplex);
}
Create pen object that you want to use and pass it some thing like
Pen p=new Pen(Color.Blue); Or
DrawComplexNumber(this.CreateGraphics(),Pens.Blue, mValReal, mValComplex);
but why you want to create the pen inn Paint event and pass it to drawing function why not make it directly in the Drawing function as i did not see that you create the pen base on user selection or other properties
MCAD
|
|
|
|
|