Ahojte, ja by som mal tiez otazku. Mam za ulohu vyplnanie pravouhlej oblasti(obdlznika) semienkovym riadkovym algoritmom. S cim si neviem rady, to je vykreslenie toho obdlznika. TU je moj kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Bitmap pozadie;
public Form1()
{
InitializeComponent();
}
System.Drawing.Rectangle obdlznik = new Rectangle( );
private void Program(object sender, EventArgs e)
{
pozadie = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics GFX = Graphics.FromImage(pozadie);
}
private void Bod_X_TextChanged(object sender, EventArgs e)
{
}
private void Bod_Y_TextChanged(object sender, EventArgs e)
{
}
private void Bod_A_TextChanged(object sender, EventArgs e)
{
}
private void Bod_B_TextChanged(object sender, EventArgs e)
{
}
private void Rozmery(object sender, EventArgs e)
{
if (Bod_A.Text != string.Empty && Bod_B.Text != string.Empty)
{
int a;
int b;
a = Convert.ToInt32(Bod_A.Text);
b = Convert.ToInt32(Bod_B.Text);
Size s = new Size(a, b);
obdlznik.Size = s;
MessageBox.Show("Rozmery boli nastavene.");
}
else
MessageBox.Show("Zadajte prosim hodnoty.");
}
private void pictureBox1_Click(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Right:
{
Size s = new Size();
s = obdlznik.Size;
Point p = new Point();
p = obdlznik.Location;
Graphics GFX = this.pictureBox1.CreateGraphics();
Pen pero = new Pen(System.Drawing.Color.Black, 1f);
Rectangle rect = new Rectangle(p,s);
GFX.DrawRectangle(pero, rect);
Size d = new Size();
d = obdlznik.Size;
MessageBox.Show("current size \n" + "Height:" + s.Height.ToString() + "Width:" + s.Width.ToString());
}
break;
case MouseButtons.Left:
{
int x = 0;
int y = 0;
x = Cursor.Position.X;
y = Cursor.Position.Y;
Point p = new Point(x, y);
obdlznik.Location = p;
MessageBox.Show("Pociatocny bod bol nastaveny.");
}
break;
}
}
}
}
Je to este len velmi zaciatocny kod. Neviem si rady konkretne s tymto: System.Drawing.Rectangle obdlznik = new Rectangle( );
Vstupne hodnoty sa maju zadavat cez Textbox. Ked do zatvorky zapisem hodnoty, tak mi to vykresli obdlznik, ale ked sa pokusam hodnoty ziskat z Textboxu, tak mi nic nepriradi. Vedel by mi niekto pomoct? Pripadne nejaky jednoduchejsi sposob ziskania rozmerov obdlznika? DAkujem vopred