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.....


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);                       
                    }                
            }
        }

Open in new window

OMR.bmp
LVL 6
nandithaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CuteBugCommented:
Use separate pens to draw the bubble and to draw the characters.
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.
0
nandithaaAuthor Commented:
I tried it, but not working.... Please help me....
0
CuteBugCommented:
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.Transparent, 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.Transparent, graphicsPath); should be either within the "if" condition or within the "else" condition based on what (itemtype == "REPLCHAR") means.

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

nandithaaAuthor Commented:
"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
0
CuteBugCommented:
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);                       
                    }                
            }
        }

Open in new window

0
nandithaaAuthor Commented:
I've tried this, but not working...
0
CuteBugCommented:
I tried a sample application with the above piece of code and it is working fine.

I have attached the code... when the code is executed it shows the number 2 in a bubble.

    public partial class Form1 : Form
    {
        GraphicsPath m_TextPath = null;
        GraphicsPath m_BubblePath = null;

        public Form1()
        {
            InitializeComponent();

            m_TextPath = GetGraphicsPath();

            m_BubblePath = new GraphicsPath();
            m_BubblePath.AddEllipse(30, 30, 20, 20);
        }

        private GraphicsPath GetGraphicsPath()
        {
            StringFormat format = StringFormat.GenericDefault;

            FontFamily fontfamily = new FontFamily("Arial");

            GraphicsPath gp = new GraphicsPath();
            gp.AddString("2", fontfamily, 1, 15, new Point(33, 32), format);

            return gp;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            if ((m_TextPath != null) && (m_BubblePath != null))
            {
                e.Graphics.FillPath(Brushes.Black, m_TextPath);
                e.Graphics.DrawPath(new Pen(Color.Black, 1), m_TextPath);
                e.Graphics.DrawPath(new Pen(Color.Black, 2), m_BubblePath);
            }

        }
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CuteBugCommented:
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.
0
CuteBugCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.