|
Hi,
While drawing treenodes, I'm having difficulties drawing the the boxes with pluses and minuses for node expansion. And also, I'm unable to simulate the hottracking action for each node when mousing over. Can you please help?
thank you
|
|
|
|
|
You need to elaborate your scenario to understand the problem u r facing
|
|
|
|
|
Maybe this code should help you to understand... :
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
....
if ((e.Node != null) && (e.Node is MyTreeNode))
{
MyTreeNode myTreeNode = e.Node as MyTreeNode;
Rectangle bounds = e.Bounds;
if (myTreeNode.CHECKBOX == true)
{
ControlPaint.DrawCheckBox(e.Graphics, bounds.Left, bounds.Top, 16, 16, ButtonState.Checked);
bounds = Rectangle.Inflate(bounds, 16, 0);
}
// Draw the background and node text for a selected node.
if ((e.State & TreeNodeStates.Selected) != 0)
{
// Draw the background of the selected node. The NodeBounds
// method makes the highlight rectangle large enough to
// include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.BlueViolet, bounds);
// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = this.Font;
// Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(bounds, 2, 0));
}
// Use the default background and node text.
else
{
e.DrawDefault = true;
}
// If a node tag is present, draw its string representation
// to the right of the label text.
//e.Graphics.DrawString(e.Node.Tag.ToString(), this.Font,
// Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top);
// If the node has focus, draw the focus rectangle large, making
// it large enough to include the text of the node tag, if present.
if ((e.State & TreeNodeStates.Focused) != 0)
{
using (Pen focusPen = new Pen(Color.Black))
{
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
Rectangle focusBounds = bounds;
focusBounds.Size = new Size(focusBounds.Width - 1, focusBounds.Height - 1);
e.Graphics.DrawRectangle(focusPen, focusBounds);
}
}
}
else
{
e.DrawDefault = true;
}
}
|
|
|
|
|
thanks. So I guess if I want those boxes with plus/minus to the left of the node for expansion and contraction, I need to draw them myself.
|
|
|
|
|
xilefxilef wrote: I need to draw them myself
That's what 'OwnerDrawm' is all about
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
hi, is it possible not to allow text selection and cursor blinking in textboxes when clicked? The problem is; with one click cursor places in the textbox and with double click text in the textbox is selected and highlighted. I just want nothing to happen when clicked
|
|
|
|
|
Use a Label control instead?
|
|
|
|
|
well, shame on me why didn't I think of that!
|
|
|
|
|
Or disable it. I think you can still set the background and foreground colors so it isn't greyed out.
|
|
|
|
|
Hi,
i have a string in this format YYYYMMDD HH:MM:SS how can i convert this string in a datetime ?
thanks for help.
|
|
|
|
|
I'm not going to spoon feed you, however I can recommend this little article[^].
|
|
|
|
|
When it comes to these type of questions... GOOGLE is your best friend!
|
|
|
|
|
I am new to this whole regex thing. I have read up on it but i still need some help. I have expressions (shown below) and I want to get the values (substring). For example, in example 1 i want to search for my property ([[[MyProperty1]]]) and I want to get back 'Value'. In example 2, i want to be able to search for [[[MyProperty2]]] and have value2 as the result.
Cant you help me write the pattern as well as explain to me what is being done in the pattern to acheive this goal. I have tried '(?<=\[{3}MyProperty1).*?(?=<\]{3})' but it does not work.
Thanks in advance.
Example 1: [[[MyProperty1]]] Value
Example 2: [[[MyProperty1]]] Value [[[MyProperty2]]] value2 [[[MyProperty3]]] value 3
|
|
|
|
|
The main problem may be that [ and ] are special characters in RegEx and need to be escaped \[ and \] .
Oh, I see you did.
I'm unfamiliar with <= and =< , but I just whipped this (?:\[\[\[(?'Name'.*?)\]\]\](?'Value'[^\[]*)) up with my RegexTester[^].
modified on Friday, April 9, 2010 1:20 PM
|
|
|
|
|
I used the escape sequence for the [. If I run '\[{3}MyProperty\]{3}, I get back '[[[MyProperty]]]'. So I think it may be something else. I think it may be the fact that I am trying to use lookahead/lookback.
|
|
|
|
|
Fayu wrote: I am trying to use lookahead/lookback
Why would you?
|
|
|
|
|
I found an example on the web which used that to get the substring. Again, I am new to this. What would you suggest?
|
|
|
|
|
What I added to my first response.
|
|
|
|
|
I didnt realize you updated your comment.
The 'Value' is unknown, can I use * as a wild card?
|
|
|
|
|
What I provided returns everything between the ]]] and the next [ or the end of the line.
|
|
|
|
|
I think (\[\[\[MyProperty3\]\]\][\s{1}])(?<MyProperty3>.*?(?=\s{1}\[|$)) is enough for both of ur requirements, if i understood it clearly
something like ...
Regex regex = new Regex(@"(\[\[\[MyProperty3\]\]\][\s{1}])(?<MyProperty3>.*?(?=\s{1}\[|$))");
Match regexmatch = regex.Match(@"[[[MyProperty1]]] Value [[[MyProperty2]]] value2 [[[MyProperty3]]] value 3");
regexmatch.Groups["MyProperty3"].Value
It'd work for values like value, value2 and value 3 as well.
Mark as answer if it answers ur question
modified on Friday, April 9, 2010 3:18 PM
|
|
|
|
|
I prefer a more generalized technique.
|
|
|
|
|
The property name is looks like this [[[MyProperty2]]] but does not end with <MyProperty2>. So the property/value item shows up as [[[MyProperty2]]] Value2. So if there are multiple properties it will look like this: [[[MyProperty1]]] Value1 [[[MyProperty2]]] Value2 [[[MyProperty3]]] Value3.
Having said that, the pattern provided did not work because I think it is looking for <MyProperty2> end tag. One other thing I want to point out is that there can be only one property which can or cannot have a space after it.
My requirements:
1) Get the value of a property if only one propery is listed ([[[MyProperty1]]] value1)
2) Get the value of a property if there are more than one properies listed ([[[MyProperty1]]] value1 [[[MyProperty2]]] value2 [[[MyProperty3]]] value3
3) In the pattern, I want to pass in the property name and get back the value
4) Use VBScript.RegexExp object (which I dont think will make a difference when it comes to pattern)
Thanks so much for assisting me with this.
|
|
|
|
|
I understand <myproperty2> is not in string of properties. Its a Named capture group literal in regex used to store matched strings under that name provided inside <>
This solution does worked with
MyProperty1, MyProperty2 and MyProperty3.
Try it urself !!!
Note: To get value of property, replace #### from
(\[\[\[####\]\]\][\s{1}])(?<####>.*?(?=\s{1}\[|$)) to that name
Example
To get MyProperty3
use regex (\[\[\[MyProperty3\]\]\][\s{1}])(?<MyProperty3>.*?(?=\s{1}\[|$))
Search for Named capture groups to understand use of <> in regex.
Edit: I have updated it lil bit to take care of end of line as well.
|
|
|
|
|
I wrote a pattern that works as well thanks to you and everyone else that helped me out. THANKS!
Here is my pattern in case you want to see it (and let me know if im missing something):
\[{3}MyProperty1\]{3} ([^ ]+)
|
|
|
|