|
You can't cast a TreeNode to a TextBox .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Sorry replied to myself....
Another not-so-simple resolution would be to create your own TextBox and handle the edits yourself.
private void tvTestTree_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.EndEdit(true);
TextBox MyEdit= new TextBox();
Rectangle IRect = e.Node.Bounds;
MyEdit.Location= new Point(IRect.X,IRect.Y);
MyEdit.Width=IRect.Width+20;
MyEdit.Height=IRect.Height;
MyEdit.Text=e.Node.Text;
tvTestTree.Controls.Add(MyEdit);
}
You will probably have to add an event handler for the TextBox to close it and
get the selected text...
|
|
|
|
|
This should work, but you can also get the edit control (a TextBox in .NET) that the Tree-View common control uses during label edits by handling the TVN_BEGINLABELEDIT notification message in TreeView.WndProc and then call a P/Invoked SendMessage with the TVM_GETEDITCONTROL :
public class MyTreeView : TreeView
{
private TextBox editBox;
protected override void WndProc(ref Message m)
{
if (m.Msg == TVN_BEGINLABELEDIT)
{
IntPtr hWnd = SendMessage(this.Handle, TVN_BEGINLABELEDIT, 0, 0);
if (hWnd != IntPtr.Zero)
this.editBox = (TextBox)Control.FromHandle(hWnd);
}
else if (m.Msg == TVN_ENDLABELEDIT)
this.editBox = null;
}
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam,
int lParam);
private const TVN_BEGINLABELEDIT = 0x10c5;
private const TVN_ENDLABELEDIT = 0x10c4;
private const TVM_GETEDITCONTROL = 0x110f;
} This way, you're not overlapping controls which can lead to problems, and you'll have to handle all the getting and setting of text.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This method is what I was referring to when I suggested casting the TreeNode edit control to a TextBox, except you said it correctly, I didn't. My Appologies....
|
|
|
|
|
Sorry, I had to work.....
Thank you both for your ideas. I'll try both of your solutions. I thought already at this. But I hoped to get an easier solution.
Whatever thanks for your efforts...
Frank
|
|
|
|
|
I'd like to perform the following function but without using a temporary text file, can someone point me towards how to do this in memory ? Is it possible ?
private void FillClipBoard()
{
string Line;
bool FoundDollar=false,Start=false;
TextReader trFile = File.OpenText(WorkingDir+CurrentName);
StreamWriter sw = File.AppendText(WorkingDir+"Clipboard.txt");
while((Line=trFile.ReadLine())!=null)
{
if(Line.StartsWith("$"))
FoundDollar=true;
if(FoundDollar)
{
if(!Start && Line.Trim().Length==0)
continue;
if(!Line.StartsWith("$"))
Start=true;
else
Start=false;
}
if(Start)
{
sw.WriteLine(Line);
}
}
sw.Close();
trFile.Close();
Utils.PutClipBoardTextFile(WorkingDir+"Clipboard.txt");
File.Delete(WorkingDir+"clipboard.txt");
}
public static void PutClipBoardTextFile(string Path)
{
TextReader tr = File.OpenText(Path);
Clipboard.SetDataObject(tr.ReadToEnd(),true);
tr.Close();
}
|
|
|
|
|
Why not just read this into a string, or better yet a StringBuilder (which is mutable). If you store the reference to this StringBuilder you can keep appending to it. Just use StringBuilder.ToString() to get the actual String .
Another way would be to use a MemoryStream and wrap your StreamWriter or StreamReader around it.
One unrelated thing to your question: instead of concatenating strings that represents directories, you should use Path.Combine to take into account the OS's path separator (\, :, /) and to ensure that - if the WorkingDir doesn't not end with a path separator - that it is added before appending the filename (or additional directory name(s)).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanx for the tip.
Does it also check whether the path start with \\ or X:?
Guess I can look that up now that I know where to look
>>>-----> MikeO
|
|
|
|
|
Hi there, I'm learning C# and I'm searching equuivalents from MFC/Win32 calls but in .NET.
1) What is the equivalent of Win32 GetSysColor() function in .NET?
2) I would like to have the equivalent in C# (.NET) of the following C++ (MFC) statement:
class CMyWindow : public CWnd
{
...
}
While CWnd is an MFC class that represents a basic window.
I want to write my own control and use it
Thanks for the help
Best regards.
|
|
|
|
|
bouli wrote:
1) What is the equivalent of Win32 GetSysColor() function in .NET?
It is System.Drawing.SystemColors class
bouli wrote:
2) I would like to have the equivalent in C# (.NET) of the following C++ (MFC) statement:
class CMyWindow : public CWnd
{
...
}
While CWnd is an MFC class that represents a basic window.
I want to write my own control and use it
Use System.Windows.Forms.Form for forms(dialogs). But for controls like button, user-controls use System.Windows.Forms.UserControl or Control. Here big difference between MFC and .NET. In MFC can be CWnd dialog and control(I used these for nested dialogs - one dialog owns another), but in .NET only classes delivered from System.Windows.Forms.Form can be dialogs and cannot contain any forms.
Wizard_01
|
|
|
|
|
ok for System.Drawing.SystemColors...
But I don't get it for the derived control.
What I wanna do is to write my own control that will get some methods. these methods will control the drawing.
|
|
|
|
|
bouli wrote:
What I wanna do is to write my own control that will get some methods. these methods will control the drawing
public class myControl : System.Windows.Forms.UserControl
{
public myControl()
{
}
....
private void Control_Paint(object sender,PaintEventHandler e)
{
}
}
Mazy
No sig. available now.
|
|
|
|
|
ok, thanks!
|
|
|
|
|
Hi,
Just one last question about this thread...
Can you show me how can I use the control in the main form?
I have inserted a label and? how can I link it to my new control?
Best regards.
Thanks.
|
|
|
|
|
bouli wrote:
I have inserted a label and? how can I link it to my new control?
What do you mean exactly? You mean you add that label to your UserControl? It is now in your .cs file as a private member. You can use it like this there:
lbale1.Text = "Hello";
User the search textbox at the top of this page to find articles in this site about UserControl for motr information.
Mazy
No sig. available now.
|
|
|
|
|
I want to use my new created control... this control graphically shows the content of an array
|
|
|
|
|
bouli wrote:
I want to use my new created control
Right click on your ToolBox and select 'Customize ToolBox' option. From .NET Component tab, with Browse button , select assembly of your control and click OK. It is now added to your toolbox and you can drag and drop it on your form.
Mazy
No sig. available now.
|
|
|
|
|
ok
I understood how to use and draw my own controls in C#
It's very different from MFC...
|
|
|
|
|
For one thing, you didn't hook-up your Paint event handlers. Remember, he's a n00b.
Also, never use events in a derived class - it's too slow and doesn't provide the control you might need (such as NOT calling the base class's OnPaint handler). Instead, always override the related method for an event when deriving from a class:
public class MyControl : UserControl
{
public MyControl()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Allows base class to paint and raise the Paint event. // Draw }
Yah, Thanks for correction.
Mazy
No sig. available now.
|
|
|
|
|
Ok, it works!!
Thanks
|
|
|
|
|
Ok, it works that way... it's almost like MFC... just override the event...;P
|
|
|
|
|
Point of clarification: OnPaint is not an event. It's a method that, in the defining class, raises the Paint event before or after optionally performing some action (like any default painting). When you override this, you pre-empt the event being raised (which is why you call base.OnPaint ) and actually override all the functionality of that method since it's virtual. If you don't call base.OnPaint , any painting that the base class, or its base class, etc., need to do won't be performed.
For more information about events in delegates in .NET, see Handling and Raising Events[^] in the MSDN Online Library.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Ok, thanks for the explainations
Thanks
|
|
|
|
|
Heath, why are events in a derived class too slow?
First, i'm assuming the fact it's derived is a nonissue, your point is just that OnPaint is exposed directly for that purpose-- let me know if i misunderstand this.
But why would events be slow, aren't they just callbacks?
TIA.
________________________________________
Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain.
Then perhaps I'd deserve ya, and be even worthy of ya..
if I only had a brain!
|
|
|
|