Custom Control (GraphicsPath and Region problem)

G

Guest

Hi All,

I need to develop a SEMI-TRIANGLE shaped of the custom button control. I
have successfully did it in full framework. However, when i'm about to do the
porting to CF, there are heaps of problems.
1. I can't find any GraphicsPath in CF
2. There is no region class which accept the graphics path datatype.

The accuracy of region is important because i need to locate the button in a
very close position with other image (otherwise, the two rectangle will
collide). I saw some example which draw the ellipse button in CF. However,
when i tried it out, it seems that it is not really ellipse because if we
click it somewhere outside the ellipse but inside the rectangle size (form),
it works.

Are there anyone have the workaround for these problems? Thank you in
advance for the helps. I would provide my code (full framework) just in case
my explanation
is confusing.

CODE:
-----------------------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;

namespace CustomUserControl
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class RightCustomTriangleButton : Control
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public RightCustomTriangleButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// RightCustomTriangleButton
//
this.Name = "RightCustomTriangleButton";
this.Size = new System.Drawing.Size(80, 72);

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
#region button coordinate
Point[] linesArea = {new Point(0, 55), new Point(0,70), new Point(55,
70), new Point(75, 52), new Point(75,2), new Point (62, 2)};
Point[] curveArea = {new Point(0, 55), new Point(20, 45), new Point(35,
34), new Point(50, 20), new Point(62, 2)};
#endregion

Pen pen = new Pen (Color.Black, 4);
GraphicsPath MyGraphPath = this.GetGraphicsPath(linesArea, curveArea);

Graphics dpc = e.Graphics;
SolidBrush textBrush = new SolidBrush(Color.Gray);
Font ft = new Font("Arial", 12, FontStyle.Bold);

dpc.DrawString("Hello", ft, textBrush, 31, 37);
dpc.DrawPath(pen, MyGraphPath);
this.Region = new Region(MyGraphPath);
}

protected override void SetBoundsCore(int x, int y, int width, int height,
BoundsSpecified specified)
{
//set the button non-resizeable
base.SetBoundsCore (x, y, 80, 72, specified);
}

private GraphicsPath GetGraphicsPath (Point[] linesArea, Point[] curveArea)
{
GraphicsPath MyPath = new GraphicsPath();
MyPath.AddLines(linesArea);
MyPath.AddCurve(curveArea);

return MyPath;
}
}
}
 
A

Alex Feinman [MVP]

Take a look here. This might work for you:
http://www.opennetcf.org/PermaLink.aspx?guid=f0abe92f-6e94-4a19-b0e3-11d1bdb3c9f0

Hendro Wijaya said:
Hi All,

I need to develop a SEMI-TRIANGLE shaped of the custom button control. I
have successfully did it in full framework. However, when i'm about to do
the
porting to CF, there are heaps of problems.
1. I can't find any GraphicsPath in CF
2. There is no region class which accept the graphics path datatype.

The accuracy of region is important because i need to locate the button in
a
very close position with other image (otherwise, the two rectangle will
collide). I saw some example which draw the ellipse button in CF. However,
when i tried it out, it seems that it is not really ellipse because if we
click it somewhere outside the ellipse but inside the rectangle size
(form),
it works.

Are there anyone have the workaround for these problems? Thank you in
advance for the helps. I would provide my code (full framework) just in
case
my explanation
is confusing.

CODE:
-----------------------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;

namespace CustomUserControl
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class RightCustomTriangleButton : Control
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public RightCustomTriangleButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// RightCustomTriangleButton
//
this.Name = "RightCustomTriangleButton";
this.Size = new System.Drawing.Size(80, 72);

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
#region button coordinate
Point[] linesArea = {new Point(0, 55), new Point(0,70), new Point(55,
70), new Point(75, 52), new Point(75,2), new Point (62, 2)};
Point[] curveArea = {new Point(0, 55), new Point(20, 45), new Point(35,
34), new Point(50, 20), new Point(62, 2)};
#endregion

Pen pen = new Pen (Color.Black, 4);
GraphicsPath MyGraphPath = this.GetGraphicsPath(linesArea, curveArea);

Graphics dpc = e.Graphics;
SolidBrush textBrush = new SolidBrush(Color.Gray);
Font ft = new Font("Arial", 12, FontStyle.Bold);

dpc.DrawString("Hello", ft, textBrush, 31, 37);
dpc.DrawPath(pen, MyGraphPath);
this.Region = new Region(MyGraphPath);
}

protected override void SetBoundsCore(int x, int y, int width, int height,
BoundsSpecified specified)
{
//set the button non-resizeable
base.SetBoundsCore (x, y, 80, 72, specified);
}

private GraphicsPath GetGraphicsPath (Point[] linesArea, Point[]
curveArea)
{
GraphicsPath MyPath = new GraphicsPath();
MyPath.AddLines(linesArea);
MyPath.AddCurve(curveArea);

return MyPath;
}
}
}
 
G

Guest

Hi Alex,

Thank you for your help.

Cheers,
Hendro


Alex Feinman said:
Take a look here. This might work for you:
http://www.opennetcf.org/PermaLink.aspx?guid=f0abe92f-6e94-4a19-b0e3-11d1bdb3c9f0

Hendro Wijaya said:
Hi All,

I need to develop a SEMI-TRIANGLE shaped of the custom button control. I
have successfully did it in full framework. However, when i'm about to do
the
porting to CF, there are heaps of problems.
1. I can't find any GraphicsPath in CF
2. There is no region class which accept the graphics path datatype.

The accuracy of region is important because i need to locate the button in
a
very close position with other image (otherwise, the two rectangle will
collide). I saw some example which draw the ellipse button in CF. However,
when i tried it out, it seems that it is not really ellipse because if we
click it somewhere outside the ellipse but inside the rectangle size
(form),
it works.

Are there anyone have the workaround for these problems? Thank you in
advance for the helps. I would provide my code (full framework) just in
case
my explanation
is confusing.

CODE:
-----------------------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;

namespace CustomUserControl
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class RightCustomTriangleButton : Control
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public RightCustomTriangleButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// RightCustomTriangleButton
//
this.Name = "RightCustomTriangleButton";
this.Size = new System.Drawing.Size(80, 72);

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
#region button coordinate
Point[] linesArea = {new Point(0, 55), new Point(0,70), new Point(55,
70), new Point(75, 52), new Point(75,2), new Point (62, 2)};
Point[] curveArea = {new Point(0, 55), new Point(20, 45), new Point(35,
34), new Point(50, 20), new Point(62, 2)};
#endregion

Pen pen = new Pen (Color.Black, 4);
GraphicsPath MyGraphPath = this.GetGraphicsPath(linesArea, curveArea);

Graphics dpc = e.Graphics;
SolidBrush textBrush = new SolidBrush(Color.Gray);
Font ft = new Font("Arial", 12, FontStyle.Bold);

dpc.DrawString("Hello", ft, textBrush, 31, 37);
dpc.DrawPath(pen, MyGraphPath);
this.Region = new Region(MyGraphPath);
}

protected override void SetBoundsCore(int x, int y, int width, int height,
BoundsSpecified specified)
{
//set the button non-resizeable
base.SetBoundsCore (x, y, 80, 72, specified);
}

private GraphicsPath GetGraphicsPath (Point[] linesArea, Point[]
curveArea)
{
GraphicsPath MyPath = new GraphicsPath();
MyPath.AddLines(linesArea);
MyPath.AddCurve(curveArea);

return MyPath;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top