Click here to Skip to main content
15,893,622 members
Home / Discussions / C#
   

C#

 
QuestionReally capturing a window Pin
bluechipmunk12-Sep-05 0:51
bluechipmunk12-Sep-05 0:51 
AnswerRe: Really capturing a window Pin
Daniel Turini12-Sep-05 1:27
Daniel Turini12-Sep-05 1:27 
QuestionBasic Insert Please correct Pin
dabuskol12-Sep-05 0:19
dabuskol12-Sep-05 0:19 
AnswerRe: Basic Insert Please correct Pin
LeenaSo12-Sep-05 0:44
LeenaSo12-Sep-05 0:44 
AnswerRe: Basic Insert Please correct Pin
mav.northwind12-Sep-05 0:46
mav.northwind12-Sep-05 0:46 
QuestionDrawing an arc Pin
11-Sep-05 23:52
suss11-Sep-05 23:52 
AnswerRe: Drawing an arc Pin
Guffa12-Sep-05 6:31
Guffa12-Sep-05 6:31 
GeneralRe: Drawing an arc Pin
subramanyeswari13-Sep-05 0:53
subramanyeswari13-Sep-05 0:53 
my rectangle co-ordinates are wrong. my arc is not coming properly. this is the code.

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

namespace FreeHand
{
///
/// Summary description for FillPolygon.
///

public class FillPolygon : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox lengthBox;
private System.Windows.Forms.TextBox angleBox;
private System.Windows.Forms.Button button1;

public Graphics m_GraphicsToDrawOn;
protected Pen m_PenToDrawWith;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox Vertical;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public FillPolygon()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
InitializeGraphics(this);


//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new FillPolygon());
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.lengthBox = new System.Windows.Forms.TextBox();
this.angleBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.Vertical = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lengthBox
//
this.lengthBox.Location = new System.Drawing.Point(776, 104);
this.lengthBox.Name = "lengthBox";
this.lengthBox.TabIndex = 0;
this.lengthBox.Text = "30";
//
// angleBox
//
this.angleBox.Location = new System.Drawing.Point(776, 136);
this.angleBox.Name = "angleBox";
this.angleBox.TabIndex = 1;
this.angleBox.Text = "270";
//
// label1
//
this.label1.Location = new System.Drawing.Point(648, 104);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "Horizontal";
//
// label2
//
this.label2.Location = new System.Drawing.Point(648, 136);
this.label2.Name = "label2";
this.label2.TabIndex = 3;
this.label2.Text = "Angle";
//
// button1
//
this.button1.Location = new System.Drawing.Point(792, 192);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(776, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 5;
this.textBox1.Text = "0";
//
// label3
//
this.label3.Location = new System.Drawing.Point(648, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 6;
this.label3.Text = "Rotate At";
//
// Vertical
//
this.Vertical.Location = new System.Drawing.Point(376, 72);
this.Vertical.Name = "Vertical";
this.Vertical.Size = new System.Drawing.Size(152, 20);
this.Vertical.TabIndex = 8;
this.Vertical.Text = "20";
//
// label4
//
this.label4.Location = new System.Drawing.Point(240, 72);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 24);
this.label4.TabIndex = 9;
this.label4.Text = "Vertical";
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// FillPolygon
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(936, 389);
this.Controls.Add(this.label4);
this.Controls.Add(this.Vertical);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.angleBox);
this.Controls.Add(this.lengthBox);
this.Name = "FillPolygon";
this.Text = "FillPolygon";
this.Load += new System.EventHandler(this.FillPolygon_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.FillPolygon_Paint);
this.ResumeLayout(false);

}
#endregion

protected void InitializeGraphics(Form canvas)
{
IntPtr formHdc = canvas.Handle;
m_GraphicsToDrawOn =Graphics.FromHwnd(formHdc);
m_PenToDrawWith = new Pen(Color.Red);
}



int horilength=0 ;
int verticallength=0;
int length = 0;
float angleDeg ;
float angleRad;
int x=100;
int y=150;

int x1=300;
int y1=250;


int r=0;
int h=0;
private double ang = 45.0f;


private void button1_Click(object sender, System.EventArgs e)
{

horilength = int.Parse(lengthBox.Text);
verticallength = int.Parse(Vertical.Text);
length =(int) (Math.Sqrt(Math.Pow(horilength,2)+(Math.Pow(verticallength,2))));

//angleDeg = Math.Max(0.0f, Math.Min(90.0f, float.Parse(angleBox.Text)));
angleDeg = float.Parse(angleBox.Text)/2;
angleRad = angleDeg * (float)(Math.PI / 180);
ang= (float)Convert.ToDouble(textBox1.Text);
//ang = Math.Tanh((verticallength/horilength)*3.14/180);


//Graphics g = this.CreateGraphics();
//Pen pen = new Pen(Color.Red, 1);


// get circle radius
r = (int) (((double) length / 2) / Math.Sin(angleRad));

//
h = (int) (Math.Cos(angleRad) * r);

// draw arc
this.Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{



int p1=0;
int p2=0;
int p3=0;
int p4=0;
float st=0;
float sp=0;
this.textBox1.Text = Convert.ToString(ang);

Point rotatePoint;

if(r!= 0)
{

// p1 = x - (r + length /2);//(r + length/2);//+int.Parse(ang.ToString());
// p2= y - (r + length /2);//(r + length/2);
p1 = x - (r - length /2);
p2= y - ( r - h);
p3 = r * 2;
p4= r * 2;//(int)Math.Sqrt(Math.Pow(length,2)-Math.Pow( r,2)) ;


st= -45 + angleDeg;
sp= -2 * angleDeg;




//e.Graphics.DrawLine(m_PenToDrawWith, x, y, x-length, y-length);
e.Graphics.DrawLine(Pens.Blue,50,y,x,y);
e.Graphics.DrawLine(m_PenToDrawWith, x, y, x+horilength, y);
e.Graphics.DrawLine(m_PenToDrawWith, x+horilength, y, x+horilength, y+verticallength);
e.Graphics.DrawLine(m_PenToDrawWith, x, y, x+horilength, y+verticallength);


//e.Graphics.DrawLine(Pens.Green,50,250,100,250);
//e.Graphics.DrawLine(Pens.Green,50,250,100,325);

rotatePoint = new Point(x,y);
//e.Graphics.DrawRectangle(Pens.Black,p1,p2,p3,p4);
Matrix myMatrix = new Matrix();


myMatrix.RotateAt((float)ang, rotatePoint, MatrixOrder.Append);
// myMatrix.Rotate(ang, MatrixOrder.Append);
e.Graphics.Transform = myMatrix;
// e.Graphics.DrawRectangle(Pens.Black,p1,p2,p3,p4);
Rectangle rect= new Rectangle(p1,p2,p3,p4);




//e.Graphics.DrawRectangle(Pens.Red,rect);
//upper side
e.Graphics.DrawArc(Pens.BlueViolet ,rect ,st ,sp);

//
// if(angleDeg *2 <180)
// {
//
// angleDeg=180-(angleDeg *2 );
// rect= new Rectangle(p1,p2-Convert.ToInt32(angleDeg),p3,p4);
//
// }

//e.Graphics.DrawArc(Pens.Black ,rect ,st ,sp);

//Second Arc
//
// e.Graphics.DrawLine(Pens.Green,x1-50,y1,x1,y1);
// p1 = x1 - (r - length / 2);//+int.Parse(ang.ToString());
// p2= y1 - (r - h) ;
//
// if(angleDeg *2 < 180)
// {
// p2=p2-(180- Convert.ToInt32(angleDeg)*2);
// rect= new Rectangle(p1,p2,p3,p4);
// }
// e.Graphics.DrawRectangle(Pens.Red,rect);
// e.Graphics.DrawArc(Pens.Black ,rect ,-st ,-sp);




// Create pen.
//Pen blackPen= new Pen(Color.Black, 2);
// Create coordinates of rectangle to bound ellipse.
// float y1 = 0.0F;
//float width = r*2;
//float height = r*2;
// Create start and sweep angles on ellipse.
// Draw arc to screen.
//e.Graphics.DrawArc(blackPen, x1, y1, width, height, startAngle, sweepAngle);


}

//m_PenToDrawWith.Dispose();
//m_GraphicsToDrawOn.Dispose();




}


private void FillPolygon_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{


}

private void FillPolygon_Load(object sender, System.EventArgs e)
{

}

private void label4_Click(object sender, System.EventArgs e)
{

}




}
}
QuestionTabIndex of multiple usercontrols Pin
JorisFromHolland11-Sep-05 23:08
JorisFromHolland11-Sep-05 23:08 
AnswerRe: TabIndex of multiple usercontrols Pin
LeenaSo12-Sep-05 0:13
LeenaSo12-Sep-05 0:13 
Question'Specified cast is not valid' Pin
Member 183980011-Sep-05 23:07
Member 183980011-Sep-05 23:07 
QuestionC# Memory Leak Mystery Pin
Jason Pease11-Sep-05 22:37
Jason Pease11-Sep-05 22:37 
AnswerRe: C# Memory Leak Mystery Pin
Zdeslav Vojkovic12-Sep-05 1:12
Zdeslav Vojkovic12-Sep-05 1:12 
AnswerRe: C# Memory Leak Mystery Pin
Guffa12-Sep-05 1:29
Guffa12-Sep-05 1:29 
AnswerRe: C# Memory Leak Mystery Pin
S. Senthil Kumar12-Sep-05 4:15
S. Senthil Kumar12-Sep-05 4:15 
GeneralRe: C# Memory Leak Mystery Pin
Jason Pease12-Sep-05 6:15
Jason Pease12-Sep-05 6:15 
GeneralRe: C# Memory Leak Mystery Pin
S. Senthil Kumar12-Sep-05 15:09
S. Senthil Kumar12-Sep-05 15:09 
QuestionCopy directories Pin
Stefan_ Spenz11-Sep-05 22:13
Stefan_ Spenz11-Sep-05 22:13 
AnswerRe: Copy directories Pin
rakesh_nits11-Sep-05 22:34
rakesh_nits11-Sep-05 22:34 
Questionmonitoring directories Pin
rakesh_nits11-Sep-05 21:51
rakesh_nits11-Sep-05 21:51 
AnswerRe: monitoring directories Pin
Dave Kreskowiak12-Sep-05 5:44
mveDave Kreskowiak12-Sep-05 5:44 
QuestionDrawing an arc Pin
11-Sep-05 21:08
suss11-Sep-05 21:08 
QuestionMail Recieve Notification Pin
mail2bourne11-Sep-05 20:34
mail2bourne11-Sep-05 20:34 
AnswerRe: Mail Recieve Notification Pin
S. Senthil Kumar11-Sep-05 21:09
S. Senthil Kumar11-Sep-05 21:09 
Questionsystem.threading.timer Pin
dhol11-Sep-05 20:02
dhol11-Sep-05 20:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.