PDA

View Full Version : سوال: برنامه نويسي گرافيكي



mahsa_cs
پنج شنبه 20 تیر 1387, 16:38 عصر
اين كد اشكالش چيه كه اجرا نميشه؟!:اشتباه:


private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen m = new Pen(Color.Black, 3);
Rectangle k1 = new Rectangle(5, 5, 110, 90);
ArrayList arr = new ArrayList();
arr.Add(k1);
Rectangle[a]=(Rectangle[])arr.ToArray(arr[0].GetType());
g.DrawRectangles(Pens.Black,a);


}

Xcalivorse
پنج شنبه 20 تیر 1387, 17:04 عصر
با این کد می خواهید چه کار بکنید.

mahsa_cs
پنج شنبه 20 تیر 1387, 17:14 عصر
ميخوام يه مستطيل بكشم و خونه بنديش كنم.

hdv212
پنج شنبه 20 تیر 1387, 17:19 عصر
آیا خطا میده ؟ متن خطا ؟

Rectangle[a]=(Rectangle[])arr.ToArray(arr[0].GetType());
فکر کنم اشکال کار شما اینجا باشه، پس نام آبجکت کجاست ؟

mahsa_cs
پنج شنبه 20 تیر 1387, 17:29 عصر
نه.خطا هم نميده.در واقع هيچ كاري نميكنه!نام ابجكت؟ دقيقا چي بايد بهش اضافه كنم؟

رافعی مهدی
پنج شنبه 20 تیر 1387, 23:49 عصر
سلام
پيشنهاد ميكنم از متد AddRectangles استفاده كنيد. كد زير را ببينيد:


/// <summary>
/// GraphicsPath.AddRectangles Method (Rectangle[])
///
/// The following code example is designed for use with Windows Forms,
/// and it requires PaintEventArgse, an OnPaint event object. The code
/// performs the following actions:
/// o Creates a path.
/// o Creates an array of rectangles and adds the rectangles to the path.
/// o Draws the path to the screen.
/// </summary>
/// <param name="e"></paramAddRectangles Method>
private void AddRectanglesExample(PaintEventArgs e)
{
// Adds a pattern of rectangles to a GraphicsPath object.
GraphicsPath myPath = new GraphicsPath();
Rectangle[] pathRects =
{
new Rectangle(20,20,100,200),
new Rectangle(40,40,120,220),
new Rectangle(60,60,240,140)
};
myPath.AddRectangles(pathRects);
// Draw the path to the screen.
Pen myPen = new Pen(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}