nandithaa
asked on
Problem with Graphics Path...
Hi everyone....
I'm trying to create templates. Each template contains a rectangle, text, small boxes and many bubbles. There are characters inside each bubble.
I'm using graphics path to draw the objects on to the panel. I want characters inside the bubble to have the pen width 1, also text to be filled completely and it should not affect the other shapes . But the problem is that while changing the pen width of text to 1, it affects the other shapes too. Other shapes are also completely filled, i want only text to be filled completely.
Please any one help me with this.....
Thanks in advance.....
I'm trying to create templates. Each template contains a rectangle, text, small boxes and many bubbles. There are characters inside each bubble.
I'm using graphics path to draw the objects on to the panel. I want characters inside the bubble to have the pen width 1, also text to be filled completely and it should not affect the other shapes . But the problem is that while changing the pen width of text to 1, it affects the other shapes too. Other shapes are also completely filled, i want only text to be filled completely.
Please any one help me with this.....
Thanks in advance.....
public void PaintShapes(Graphics graphics)
{
if (graphicsPath != null)
{
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.FillPath(Brushes.Transparent, graphicsPath);
if (itemtype == "REPLCHAR")
{
graphics.DrawPath(new Pen(Color.Black, 2), graphicsPath);
graphicsPath.FillMode = FillMode.Alternate;
//e.Graphics.DrawPath(new Pen(Color.Gray, 1), graphicsPath);
//e.Graphics.DrawPath(new Pen(Color.Black, 1), graphicsPath);
}
else
{
graphics.DrawPath(new Pen(Color.Black, 2), graphicsPath);
}
}
}
OMR.bmp
ASKER
I tried it, but not working.... Please help me....
Can you provide more code?
If I am understanding correctly, if (itemtype == "REPLCHAR") then it means you are drawing a Character, right?
In your code, you are calling graphics.FillPath(Brushes. Transparen t, graphicsPath); first, this will fill the path no matter if the path is a rectangle or a character or a bubble.
So I think graphics.FillPath(Brushes. Transparen t, graphicsPath); should be either within the "if" condition or within the "else" condition based on what (itemtype == "REPLCHAR") means.
If I am understanding correctly, if (itemtype == "REPLCHAR") then it means you are drawing a Character, right?
In your code, you are calling graphics.FillPath(Brushes.
So I think graphics.FillPath(Brushes.
ASKER
"REPLCHAR" indicates the characters inside the bubble.
I haven already tried giving FillPath inside if condition, but still not working.
I'm attaching the code along with this.... Plz go though it....
Thanks in advance....
addTools.txt
I haven already tried giving FillPath inside if condition, but still not working.
I'm attaching the code along with this.... Plz go though it....
Thanks in advance....
addTools.txt
try this way
public void PaintShapes(Graphics graphics)
{
if (graphicsPath != null)
{
graphics.SmoothingMode = SmoothingMode.HighQuality;
if (itemtype == "REPLCHAR")
{
graphics.FillPath(Brushes.Black, graphicsPath);
graphics.DrawPath(new Pen(Color.Black, 1), graphicsPath);
}
else
{
graphics.DrawPath(new Pen(Color.Black, 2), graphicsPath);
}
}
}
ASKER
I've tried this, but not working...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
After seeing your code, I can suggest some ways of improving the efficiency of the code.
For eg you are calling CreateGraphics of the pnlDraw each time you want to add a tool. This is not efficient. Instead you should try to obtain the reference to the Graphics object associated with the pnlDraw. In order to get that you should override the OnPaint method of pnlDraw. The PaintEventArgs parameter to this method has a property called Graphics which will give you the required reference.
Also, each type of tool that you are creating (rectangle, bubble, text) - have classes representing them which will store only the itemtype, origin and size and content(in case of text). Do not create a control for each.
Maintain a List in which you can fill instances of these classes based upon your requirement.
In the overridden method OnPaint() of pnlDraw, you can iterate through the List and draw them using the e.Graphics.
For eg you are calling CreateGraphics of the pnlDraw each time you want to add a tool. This is not efficient. Instead you should try to obtain the reference to the Graphics object associated with the pnlDraw. In order to get that you should override the OnPaint method of pnlDraw. The PaintEventArgs parameter to this method has a property called Graphics which will give you the required reference.
Also, each type of tool that you are creating (rectangle, bubble, text) - have classes representing them which will store only the itemtype, origin and size and content(in case of text). Do not create a control for each.
Maintain a List in which you can fill instances of these classes based upon your requirement.
In the overridden method OnPaint() of pnlDraw, you can iterate through the List and draw them using the e.Graphics.
Check this site for a similar concept
http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx
http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx
Instead of creating a Pen each time, have two member variables of type Pen. Initialize one pen with the width of 1 and the other with the width of 2.
Use the first pen to draw the rectangles and bubbles. Use the second pen to draw the characters.