PDA

View Full Version : سوال: مشکل در یک پروژه



hd2010hd
شنبه 01 آذر 1393, 21:03 عصر
سلام خدمت اساتید

ما یک پروژه داریم به این صورت عکس فرم :

125946

حالا من کدش رو تا یه جایی نوشتم ولی مشکل داره کل برنامه به این صورت هستش که نوع خط رو انتخاب میکنیم . رنگش رو توی تکست هم ضخامت خط رو ولی وقتی برنامه اجرا میکنم فقط بگ گراند رو رنگش رو عوض میکنه

اینم کد هاش ممنون میشم اشکالات کوچیکش رو حل کنید برام بزارید


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Drawing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int selectDash;
int selectColor;
int width1;
Color c;
Pen pen1;
private void setcolor()
{
switch (selectColor)
{
case 1:
c = Color.Red;
break;
case 2:
c = Color.Green;
break;
case 3:
c = Color.Blue;
break;

}
}
void setDash()
{
pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen1.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
}

private void button1_Click(object sender, EventArgs e)
{
Graphics graphic1;
graphic1 = this.CreateGraphics();
graphic1.Clear(Color.Red);
width1 = Convert.ToInt16(textBox1.Text);
setcolor();
setDash();
int i;
for(i=20,i<=220,i+=20);
{

graphic1.DrawLine(pen1,i,10,i,150);
}



private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
selectDash = 1;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
selectDash = 2;
}

private void groupBox1_Enter(object sender, EventArgs e)
{

}

private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
selectDash = 3;
}

private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
selectDash = 4;
}

private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
selectDash = 5;
}
}
}

ashkufaraz
شنبه 01 آذر 1393, 21:50 عصر
این خدمت شما!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int selectDash;
int selectColor;
Color c;
DashStyle style;
private void setcolor(
{
switch (selectColor)
{
case 1:
c = Color.Red;
break;
case 2:
c = Color.Blue;
break;
}

}

private void setDash()
{
switch (selectDash)
{
case 1:
style =DashStyle.Dash;
break;
case 2:
style =DashStyle.Solid;
break;
}
}

private void Draw_Click(object sender, EventArgs e)
{
Graphics g;

g = this.CreateGraphics();

setcolor();
Pen myPen = new Pen(c);
myPen.Width =int.Parse(Size.Text);
myPen.DashStyle = style;
g.DrawLine(myPen, int.Parse(x1.Text), int.Parse(y1.Text),int.Parse(x2.Text),int.Parse(y2 .Text));


}

private void Red_CheckedChanged(object sender, EventArgs e)
{
selectColor = 1;
}

private void Blue_CheckedChanged(object sender, EventArgs e)
{
selectColor = 2;
}

private void Dash_CheckedChanged(object sender, EventArgs e)
{
selectDash = 1;
}

private void Solid_CheckedChanged(object sender, EventArgs e)
{
selectDash = 2;
}
}
}

hd2010hd
شنبه 01 آذر 1393, 22:28 عصر
دوست عزیز ممنون ولی این کد با کد من فرق داره قسمت حلقه For منو ببینید اون تو کد شما نیست توسط اون رسم میشه وقت کنید اون تو کد شما چجوری اوکیش کنم این قسمت رو اگه میشه تو کد خودتون بزارید درستشو


Graphics graphic1;
graphic1 = this.CreateGraphics();
graphic1.Clear(Color.Red);
width1 = Convert.ToInt16(textBox1.Text);
setcolor();
setDash();
int i;
for(i=20,i<=220,i+=20);
{

graphic1.DrawLine(pen1,i,10,i,150);
}




بعد میخواستم بعد این اول که برنامه اجرا میشه با دستور if کاری کنیم یکی از گزبنه ها انتخاب شده باشه مثلا رنگ قرمز و حالت DOT

ashkufaraz
شنبه 01 آذر 1393, 22:47 عصر
حاجی میگم مطمئن هستی که این کد رو خودت نوشتی!
خوب یه خط را با for جایگزین کن دیگه

یعنی به جای

g.DrawLine(myPen, int.Parse(x1.Text), int.Parse(y1.Text),int.Parse(x2.Text),int.Parse(y2 .Text));


اینو بزار

int i;
for (i = 20; i <= 220; i += 20) ;
{

g.DrawLine(myPen, i, 10, i, 150);
}

hd2010hd
شنبه 01 آذر 1393, 22:50 عصر
اقا ببخشید اره خودم نوشتم حلش کردم مرسی