1

Тема: с# программы - несколько готовых лабораторных работ.

Программа после нажатя на форме мыши определяет координаты курсора

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

namespace Laba_AlexSys_1
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(272, 8);
            this.label1.Name = "label1";
            this.label1.TabIndex = 0;
            this.label1.Text = "Верхний - правый";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(280, 264);
            this.label2.Name = "label2";
            this.label2.TabIndex = 1;
            this.label2.Text = "Нижний - правый";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(8, 264);
            this.label3.Name = "label3";
            this.label3.TabIndex = 2;
            this.label3.Text = "Нижний - левый";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(8, 8);
            this.label4.Name = "label4";
            this.label4.TabIndex = 3;
            this.label4.Text = "Верхний - левый";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(384, 293);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label4,
                                                                          this.label3,
                                                                          this.label2,
                                                                          this.label1});
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

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

        private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.Text="Координаты курсора: (" + e.X + ". " + e.Y +")";
        }
    }
}
Post's attachments

курсор мыши.jpg, 14.21 kb, 412 x 342
курсор мыши.jpg 14.21 kb, 354 downloads since 2015-08-26 

Поделиться

2

Re: с# программы - несколько готовых лабораторных работ.

Рисуем компьютер в трех проекциях

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

namespace Laba_AlexSys_2
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //CenterToScreen();
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(536, 502);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

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

        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Graphics gr = this.CreateGraphics();
            System.Drawing.Pen blue  = new Pen(Color.Blue, 1); // синее, ширина: 1
            //System.Drawing.Pen red     = new Pen(Color.Red, 2); // красное, ширина: 2
            //System.Drawing.Pen green = Pens.Green; // зелёное, ширина: 3
            gr.DrawRectangle(blue, 60,30,180,160); 
            gr.DrawRectangle(blue, 80,50,140,120);
            gr.DrawRectangle(blue, 130,190,40,60);
            gr.DrawRectangle(blue, 90,250,120,20);

            gr.DrawRectangle(blue, 340,100,100,200);
            gr.DrawRectangle(blue, 340,100,100,40);
            gr.DrawRectangle(blue, 340,140,100,40);
            gr.DrawRectangle(blue, 340,180,60,30);
            gr.DrawRectangle(blue, 340,210,60,30);
            gr.DrawEllipse(blue, 410,230,20,20);
            gr.DrawEllipse(blue, 414,260,12,12);


            gr.DrawRectangle(blue, 320,340,140,100);
            gr.DrawRectangle(blue, 360,360,40,60);
            gr.DrawRectangle(blue, 360,360,20,20);
            gr.DrawRectangle(blue, 380,360,20,20);

            gr.DrawRectangle(blue, 60,340,220,100); 
            gr.DrawRectangle(blue, 60,360,220,20);
            gr.DrawRectangle(blue, 60,400,220,20);
            gr.DrawRectangle(blue, 80,340,20,100);
            gr.DrawRectangle(blue, 120,340,20,80);
            gr.DrawRectangle(blue, 160,340,20,80);
            gr.DrawRectangle(blue, 200,340,20,80);
            gr.DrawRectangle(blue, 240,340,20,100);


        }
    }
}
Post's attachments

Компьютер проекции.jpg, 30.65 kb, 564 x 556
Компьютер проекции.jpg 30.65 kb, 351 downloads since 2015-08-26 

Поделиться

3

Re: с# программы - несколько готовых лабораторных работ.

Рисуем на форме кнопочки:

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

namespace Laba_AlexSys_3
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem menuItem2;
        private System.Windows.Forms.MenuItem menuItem3;
        private System.Windows.Forms.MenuItem menuItem4;
        private System.Windows.Forms.MenuItem menuItem5;
        private System.Windows.Forms.MenuItem menuItem6;
        private System.Windows.Forms.MenuItem menuItem7;
        private System.Windows.Forms.MenuItem menuItem8;
        private System.Windows.Forms.MenuItem menuItem9;
        private System.Windows.Forms.MenuItem menuItem10;
        private System.Windows.Forms.MenuItem menuItem11;
        private System.Windows.Forms.MenuItem menuItem12;
        private System.Windows.Forms.MenuItem menuItem13;
        private System.Windows.Forms.ToolBar toolBar1;
        private System.Windows.Forms.ToolBarButton toolBarButton1;
        private System.Windows.Forms.ToolBarButton toolBarButton2;
        private System.Windows.Forms.ToolBarButton toolBarButton3;
        private System.Windows.Forms.ToolBarButton toolBarButton4;
        private System.Windows.Forms.ToolBarButton toolBarButton6;
        private System.Windows.Forms.ToolBarButton toolBarButton7;
        private System.Windows.Forms.ToolBarButton toolBarButton8;
        private System.Windows.Forms.ToolBarButton toolBarButton9;
        private System.Windows.Forms.ToolBarButton toolBarButton10;
        private System.Windows.Forms.ToolBarButton toolBarButton11;
        private System.Windows.Forms.ImageList imageList1;
        private System.ComponentModel.IContainer components;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            this.components = new System.ComponentModel.Container();
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            this.menuItem10 = new System.Windows.Forms.MenuItem();
            this.menuItem11 = new System.Windows.Forms.MenuItem();
            this.menuItem12 = new System.Windows.Forms.MenuItem();
            this.menuItem13 = new System.Windows.Forms.MenuItem();
            this.toolBar1 = new System.Windows.Forms.ToolBar();
            this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton9 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton10 = new System.Windows.Forms.ToolBarButton();
            this.toolBarButton11 = new System.Windows.Forms.ToolBarButton();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.SuspendLayout();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem1,
                                                                                      this.menuItem3,
                                                                                      this.menuItem7,
                                                                                      this.menuItem13});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem2});
            this.menuItem1.Text = "Окно";
            // 
            // menuItem2
            // 
            this.menuItem2.Index = 0;
            this.menuItem2.Text = "Форма 1";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 1;
            this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem4,
                                                                                      this.menuItem5,
                                                                                      this.menuItem6});
            this.menuItem3.Text = "Размер окна";
            // 
            // menuItem4
            // 
            this.menuItem4.Index = 0;
            this.menuItem4.Text = "Развернуть";
            // 
            // menuItem5
            // 
            this.menuItem5.Index = 1;
            this.menuItem5.Text = "Свернуть";
            // 
            // menuItem6
            // 
            this.menuItem6.Index = 2;
            this.menuItem6.Text = "Во весь экран";
            // 
            // menuItem7
            // 
            this.menuItem7.Index = 2;
            this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem8,
                                                                                      this.menuItem9,
                                                                                      this.menuItem10,
                                                                                      this.menuItem11,
                                                                                      this.menuItem12});
            this.menuItem7.Text = "Правка";
            // 
            // menuItem8
            // 
            this.menuItem8.Index = 0;
            this.menuItem8.Text = "Переименовать форму";
            // 
            // menuItem9
            // 
            this.menuItem9.Index = 1;
            this.menuItem9.Text = "Изменить область формы";
            this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
            // 
            // menuItem10
            // 
            this.menuItem10.Index = 2;
            this.menuItem10.Text = "Сделать Видимой";
            // 
            // menuItem11
            // 
            this.menuItem11.Index = 3;
            this.menuItem11.Text = "Сделать невидимой";
            // 
            // menuItem12
            // 
            this.menuItem12.Index = 4;
            this.menuItem12.Text = "Изменить фон";
            // 
            // menuItem13
            // 
            this.menuItem13.Index = 3;
            this.menuItem13.Text = "Выход";
            // 
            // toolBar1
            // 
            this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
                                                                                        this.toolBarButton1,
                                                                                        this.toolBarButton2,
                                                                                        this.toolBarButton3,
                                                                                        this.toolBarButton4,
                                                                                        this.toolBarButton6,
                                                                                        this.toolBarButton7,
                                                                                        this.toolBarButton8,
                                                                                        this.toolBarButton9,
                                                                                        this.toolBarButton10,
                                                                                        this.toolBarButton11});
            this.toolBar1.ButtonSize = new System.Drawing.Size(22, 24);
            this.toolBar1.DropDownArrows = true;
            this.toolBar1.ImageList = this.imageList1;
            this.toolBar1.Name = "toolBar1";
            this.toolBar1.ShowToolTips = true;
            this.toolBar1.Size = new System.Drawing.Size(292, 27);
            this.toolBar1.TabIndex = 0;
            this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
            // 
            // toolBarButton1
            // 
            this.toolBarButton1.Text = "Форма1";
            this.toolBarButton1.ToolTipText = "Форма1";
            // 
            // toolBarButton2
            // 
            this.toolBarButton2.ImageIndex = 4;
            this.toolBarButton2.ToolTipText = "Во весь экран";
            // 
            // toolBarButton3
            // 
            this.toolBarButton3.ImageIndex = 0;
            this.toolBarButton3.ToolTipText = "Свернуть";
            // 
            // toolBarButton4
            // 
            this.toolBarButton4.ImageIndex = 1;
            this.toolBarButton4.ToolTipText = "Развернуть";
            // 
            // toolBarButton6
            // 
            this.toolBarButton6.ImageIndex = 6;
            this.toolBarButton6.ToolTipText = "Переименовать форму";
            // 
            // toolBarButton7
            // 
            this.toolBarButton7.ImageIndex = 5;
            this.toolBarButton7.ToolTipText = "Изменить границу формы";
            // 
            // toolBarButton8
            // 
            this.toolBarButton8.ImageIndex = 4;
            this.toolBarButton8.ToolTipText = "Сделать видимой";
            // 
            // toolBarButton9
            // 
            this.toolBarButton9.ImageIndex = 3;
            this.toolBarButton9.ToolTipText = "Сделать невидимой";
            // 
            // toolBarButton10
            // 
            this.toolBarButton10.ImageIndex = 7;
            this.toolBarButton10.ToolTipText = "Изменить фон";
            // 
            // toolBarButton11
            // 
            this.toolBarButton11.ImageIndex = 2;
            this.toolBarButton11.ToolTipText = "Выход";
            // 
            // imageList1
            // 
            this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.toolBar1});
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

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

        private void menuItem2_Click(object sender, System.EventArgs e)
        {
            //роппро
        }

        private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            //рпрпо
        }
    }
}
Post's attachments

Форма.jpg, 18.04 kb, 327 x 341
Форма.jpg 18.04 kb, 338 downloads since 2015-08-26 

Поделиться

4

Re: с# программы - несколько готовых лабораторных работ.

Закрашивание елочки разными цветами - текстурой, градиентом, штрихами..

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

namespace Laba_AlexSys_4
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private Brush texturedBGroundBrush;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(8, 264);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(88, 24);
            this.button1.TabIndex = 0;
            this.button1.Text = "Текстурная";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(120, 264);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(96, 24);
            this.button2.TabIndex = 1;
            this.button2.Text = "Штриховая";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(240, 264);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(88, 24);
            this.button3.TabIndex = 2;
            this.button3.Text = "Градиентная";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(336, 294);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.button3,
                                                                          this.button2,
                                                                          this.button1});
            this.HelpButton = true;
            this.Name = "Form1";
            this.Text = "Form1";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread] 
        static void Main() 
        {
            Application.Run(new Form1());
        }

        int i;

        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            
        if (i == 1)
            {
            Image bGroundBrushImage = new Bitmap("D:/col.bmp");
            texturedBGroundBrush = new TextureBrush(bGroundBrushImage);

            // Выводим рисунок в обьекте
            g.FillPolygon(texturedBGroundBrush, new Point[] { new Point (170, 30), new Point(260, 120), new Point(210, 120), new Point (260, 180), new Point(210, 180), new Point(210, 240), new Point (140, 240), new Point (140, 180), new Point(80, 180), new Point(140, 120), new Point (80, 120)} );
        };
        
        if (i == 2)
            {
                // Помещаем в массив все члены перечисления HatchStyle
                Array obj = Enum.GetValues(typeof(HatchStyle));
                // Настраиваем кисть
                HatchStyle temp = (HatchStyle)obj.GetValue(4);
                HatchBrush theBrush = new HatchBrush(temp, Color.White, Color.Black);
                // Закрашиваем эллипс штриховой кистью
                g.FillPolygon(theBrush, new Point[] { new Point (170, 30), new Point(260, 120), new Point(210, 120), new Point (260, 180), new Point(210, 180), new Point(210, 240), new Point (140, 240), new Point (140, 180), new Point(80, 180), new Point(140, 120), new Point (80, 120)} );
            };

        if (i == 3)
            {
                Rectangle r = new Rectangle(0,10,100,100);
                LinearGradientBrush theBrush = null;
                // Получаем все значения перечисления LinearGradientMode
                Array obj = Enum.GetValues(typeof(LinearGradientMode));
                // Настраиваем кисть
                LinearGradientMode temp = (LinearGradientMode)obj.GetValue(2);
                theBrush = new LinearGradientBrush(r, Color.Red, Color.Blue, temp);
                // Заполняем прямоугольник при помощи градиентной кисти
                g.FillPolygon(theBrush, new Point[] { new Point (170, 30), new Point(260, 120), new Point(210, 120), new Point (260, 180), new Point(210, 180), new Point(210, 240), new Point (140, 240), new Point (140, 180), new Point(80, 180), new Point(140, 120), new Point (80, 120)} );
        };
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            i=1;
//            Form1_Paint(sender);
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            i=2;
//            this.OnPaint;
        }

        private void button3_Click(object sender, System.EventArgs e)
        {
            i=3;
//            this.OnPaint;
        }

        }
        }
    
Post's attachments

Елочка градиент.jpg, 16.75 kb, 365 x 351
Елочка градиент.jpg 16.75 kb, 355 downloads since 2015-08-26 

Поделиться

5

Re: с# программы - несколько готовых лабораторных работ.

Внутри формы двигаются влево/вправо курсор и мышка.

using System;
using System.Drawing;
using System.Threading;//добавляем для использования задержки
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;



namespace Laba_AlexSys_2
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //CenterToScreen();
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(536, 502);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

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

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

            System.Drawing.Graphics gr = this.CreateGraphics();
            System.Drawing.Pen blue  = new Pen(Color.Blue, 1); // синее, ширина: 1
            
            Graphics displayGraphics = e.Graphics;
             int k=340;
            int ki=1;
            while(ki != 2)
            {
                SolidBrush b= new SolidBrush(Color.Yellow);
                Image i = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                Graphics g = Graphics.FromImage(i);
                g.Clear(Color.Lime);
                Thread.Sleep(100);//задержка на 300 миллисекунд

                g.DrawRectangle(blue, 60,30,180,160); 
                g.DrawRectangle(blue, 80,50,140,120);
                g.DrawRectangle(blue, 130,190,40,60);
                g.DrawRectangle(blue, 90,250,120,20);

                g.DrawRectangle(blue, 340,100,100,200);
                g.DrawRectangle(blue, 340,100,100,40);
                g.DrawRectangle(blue, 340,140,100,40);
                g.DrawRectangle(blue, 340,180,60,30);
                g.DrawRectangle(blue, 340,210,60,30);
                g.DrawEllipse(blue, 410,230,20,20);
                g.DrawEllipse(blue, 414,260,12,12);

                g.DrawRectangle(blue, 320,340,140,100);
                g.DrawRectangle(blue, k,360,40,60);
                g.DrawRectangle(blue, k,360,20,20);
                g.DrawRectangle(blue, k+20,360,20,20);

                g.DrawPolygon(blue, new Point[] { new Point (90 + 10 + k - 340, 80 + 10), new Point(90 + 25 + k - 340, 80 + 15),new Point(90 + 18 + k - 340, 80 + 18), new Point (90 + 35 + k - 340, 80 + 35), new Point(90 + 30 + k - 340, 80 + 40), new Point(90 + 12 + k - 340, 80 + 22), new Point (90 + 7 + k - 340, 80 + 25)  } );

                g.DrawRectangle(blue, 60,340,220,100); 
                g.DrawRectangle(blue, 60,360,220,20);
                g.DrawRectangle(blue, 60,400,220,20);
                g.DrawRectangle(blue, 80,340,20,100);
                g.DrawRectangle(blue, 120,340,20,80);
                g.DrawRectangle(blue, 160,340,20,80);
                g.DrawRectangle(blue, 200,340,20,80);
                g.DrawRectangle(blue, 240,340,20,100);

                if (ki == 1)
                    k=k+5;
                    else k=k-5;
                if (k >= 400)
                    ki = 0;
                if (k <= 340)
                    ki = 1;
                //выводим на форму, созданное изображение
                displayGraphics.DrawImage(i, ClientRectangle);    
            }

        }
    }
}
Post's attachments

Движение мышки и курсора.jpg, 28.92 kb, 561 x 559
Движение мышки и курсора.jpg 28.92 kb, 349 downloads since 2015-08-26 

Поделиться

6

Re: с# программы - несколько готовых лабораторных работ.

При нажатии кнопки форма двигается в указанный угол экрана.

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

namespace WindowsApplication3
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Button button5;
        private System.ComponentModel.IContainer components;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent 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 Windows Form 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()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(40, 48);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(56, 40);
            this.button1.TabIndex = 0;
            this.button1.Text = "Вверх - Влево";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(160, 48);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(56, 40);
            this.button2.TabIndex = 1;
            this.button2.Text = "Вверх - Вправо";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(40, 128);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(56, 40);
            this.button3.TabIndex = 2;
            this.button3.Text = "Вниз - Влево";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(160, 128);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(56, 40);
            this.button4.TabIndex = 3;
            this.button4.Text = "Вниз - Вправо";
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // button5
            // 
            this.button5.Location = new System.Drawing.Point(104, 96);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(56, 24);
            this.button5.TabIndex = 4;
            this.button5.Text = "Центр";
            this.button5.Click += new System.EventHandler(this.button5_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(296, 206);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.button5,
                                                                          this.button4,
                                                                          this.button3,
                                                                          this.button2,
                                                                          this.button1});
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            int i;
            while((this.Top > 0) && (this.Left > 0))
            {
                this.Top=this.Top - 2;
                this.Left = this.Left - 2;
                for(i=1; i<1500000; i++);
            }

        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            int i;
            while((this.Top > 0) && (this.Right <1024))
            {
                this.Top=this.Top - 2;
                this.Left = this.Left + 2;
                for(i=1; i<1500000; i++);
            }
        }

        private void button4_Click(object sender, System.EventArgs e)
        {
            int i;            
            while((this.Top + this.Height < 768) && (this.Right < 1024))
            {
                this.Top=this.Top + 2;
                this.Left = this.Left + 2;
                for(i=1; i<1500000; i++);
            }
        }

        private void button3_Click(object sender, System.EventArgs e)
        {
            int i;
            while((this.Top + this.Height < 768) && (this.Left > 0))
            {
                this.Top=this.Top + 2;
                this.Left = this.Left - 2;
                for(i=1; i<1500000; i++);
            }
        }

        private void button5_Click(object sender, System.EventArgs e)
        {
            this.Top=250;
            this.Left = 350;
        }

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

        }
    }
}
Post's attachments

Движение формы.jpg, 11.9 kb, 325 x 264
Движение формы.jpg 11.9 kb, 352 downloads since 2015-08-26 

Поделиться