|
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
|
|
|
|
|
Thanks for your answer..I think I'm beginning to get it...
Q."why you want to create the pen inn Paint event and pass it to drawing function "
A.Because I want to use the DrawComplexNumber(..) method to draw more than one color for many lines (I have several text boxes each associated w/ Button event and I need a different color for each one. BUT, if possible, I only want ONE DrawComplexNumber(..) method passed to the Paint handler.
|
|
|
|
|
correction
Each TextBox has ITS OWN buton event i.e
TextBox1.Text has OnTextChanged.btn1
TextBox2.Text has OnTextChanged.Btn2 etc....
|
|
|
|
|
If I understood you correctly you need to do the following
At the form level Create Pen object
Private Pen penActive;
when the user Press the Button set the pen to the color you want
penActive=new Pen(Color.Blue);
in your paint code pass the pen to the drawing function
DrawComplexNumber(parm1,parm2,penActive)
and after you finsh your work Call
penActive.Dispose();
MCAD
-- modified at 16:29 Saturday 10th September, 2005
|
|
|
|
|
Many thanks -- what you said works, BUT when I try to call
DrawComplexNumber in the Paint handler it doesn't see "re" or "im_"...also have I messed up on declaring a Graphics g
though I get no error......
....private Pen activePen;
....private mValReal;
....privatemValComplex;
////////////////////////////////////////////////////////////////////////
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(), activePen, re_, im_) ;
}
}
///////////////////////////////////////////////////////////////////////////////////
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen activePen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
//DOES THIS LINE BELOW GO IN Form1_Paint OR HERE??
//DrawComplexNumber(g,activePen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
////////////////////////////////////////////////////////////////////////////////
void DrawComplexNumber(Graphics g, Pen activePen, double re_, double im_)
{
g.DrawLine(activePen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
|
|
|
|
|
Anonymous wrote:
it doesn't see "re" or "im_"...
What did you mean with did not see them
Anonymous wrote:
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen activePen = new Pen(Color.Coral, 4);
Note: this code will create new activePen object instead ours so write it like this
activePen = new Pen(Color.Coral, 4);
ie remove the forward Pen
MCAD
|
|
|
|
|
Anonymous wrote:
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(), activePen, re_, im_) ;
}
}
did you mean re_ and im_ you pass here of course it will not see them if you want variable to be visible in more function declare them at the higher level in your case declare them in form level or declare another two variable in paint event and set thier values and then pass them to function
in general do not declare variable in scope higher than its need
seconed thing give your variables more meaning names
MCAD
-- modified at 19:15 Saturday 10th September, 2005
|
|
|
|
|
I have a method that returns a value of type object . The value will be an integer, unless it is null . That's why I want to convert it a nullable type (int? ).
Casting doesn't work:
object result = GetValue();
int? i = (int?)result;
I get an InvalidCastException. What's the right way to do it?
Thanks in advance,
Alvaro
I cannot take anything the Bush administration does seriously. The corruption, the cynical disregard for humanity, the cronyism and incompetence, all wrapped in a slimey flag of ultra-marketed nationalism repulses me. -- consdubya from fark.com.
-- modified at 14:02 Saturday 10th September, 2005
|
|
|
|
|
This depends on what version of .NET you are using.
In Beta 2, nullables box into a box(Nullable<int>); but this has changed and now nullables box into a box(int) or null reference.
So in post-beta 2 your code should work; but until then you have to use something strange like
int? i = (result != null) ? (int?)(int)result : null;
|
|
|
|
|
Thanks for you quick response. Your suggestion worked.
Is this Post-Beta 2 version you mentioned available? How can I get it?
I cannot take anything the Bush administration does seriously. The corruption, the cynical disregard for humanity, the cronyism and incompetence, all wrapped in a slimey flag of ultra-marketed nationalism repulses me. -- consdubya from fark.com.
|
|
|
|
|
I think the change is included in the new CTP builds only available to MSDN subscribers.
Normal people will have to wait for the release of .NET 2.0.
|
|
|
|
|
Hello,
anybody tried develop OCR algorithms used with retrieving window information from external WIN32 applications?
Need some help related to documentation, basics and algorithms.
Thank you.
|
|
|
|
|
Hello, I was wondering if there is a way to create a folder in C#. I know its possible to create a file, but is there a way to create and delete a folder. Also, is there a way to lock temporary created items so that they can't be modified? (doing all of this in C#)
|
|
|
|
|
1. System.IO.Directory.CreateDirectory
2. When you open a file use FileStream and use the FileShare.None fileShare parameter.
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
|
|
|
|
|
Hello everyone
I have read many articles about making connection to Mysql.
Many articles contain the following code, but it doesn't work when I put it into my program.
string connectionString = @"Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;";
OdbcConnection conn= new OdbcConnection(connectionString);
This looks naive. Because it doesn't define the location of the database. In the database provider there is not MySql item. Could anybody tell me a good way to make a connection from C# to MySql please? And also if I make an application in .net framework with MySql as the source database, does the client needs to install mysql when I deploy the application to his computer??
Thanks in advance
Asura
|
|
|
|
|
take a look here if you did not yet,
http://dev.mysql.com/tech-resources/articles/dotnet/#ODBC.NET
I did odbc connections to mysql from VB years ago, it should work
in C# as well because ODBC is still a standart.
ODBC driver sends requests to server and not directly
to underying database file, for db server database name is unique so it knows
where it is located.
If server is not running you should
get a connetion error(server name is one of the parameters in connect string).
if you need to distribute db with an application you might want to
use file type db like Access/Excel perhups or depending on your program logic give
user remote access to your server.
|
|
|
|