I oczywiście najważniejsze, zapamiętanie wszystkich zmian
ja niestety nie umiem korzystać z tych plików settings wbudowanych ponieważ zawsze zapisywał mi plik config gdzieś tam w użytkownikach a ja chciałbym żeby zapisywało w pliku obok aplikacji. Ale to jest na inny temat.
Edit:
Właśnie, miałem wrzucić kod. Z załączniku cały projekt a tutaj daje poszczególne funkcje.
Hmmm napisałem ze w załączniku a tu nie widzę opcji dodawania załączników.
Forma się skaluje, efekt jest jaki jest i można przesuwać obiekty.
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ScalableForm
{
public partial class Form1 : Form
{
Size Actual_size = new Size();
Size Oryginal_Size = new Size();
Point BeforeLocation = new Point();
Point AfterLocation = new Point();
bool mouse_clicked = false;
bool moved = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Oryginal_Size = this.Size;
Actual_size = this.Size;
}
void resizeControls(Control.ControlCollection control)
{
double aspectY = (double)(this.Height) / Actual_size.Height;
double aspectX = (double)(this.Width) / Actual_size.Width;
foreach (Control c in control)
{
Font f = c.Font;
c.Location = new Point((int)(aspectX * c.Location.X), (int)(aspectY * c.Location.Y));
c.Size = new Size((int)(aspectX * c.Size.Width), (int)(aspectY * c.Size.Height));
if (c.HasChildren)
{
resizeControls(c.Controls);
}
c.Font = new Font(f.FontFamily, (float)(aspectY * f.Size), f.Style, f.Unit, f.GdiCharSet, f.GdiVerticalFont);
}
}
private void Form1_Resize(object sender, EventArgs e)
{
resizeControls(this.Controls);
Actual_size = this.Size;
}
private void button1_Click(object sender, EventArgs e)
{
if (moved)
{
moved = false;
return;
}
MessageBox.Show("");
}
private void button_MouseUp(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
int x = button.Location.X + e.X;
int y = button.Location.Y + e.Y;
bool moved = !((x >= button.Location.X && x <= button.Location.X + button.Width)
&& (y >= button.Location.Y && y <= button.Location.Y + button.Height));
bool inParentControl = (x >= 0 && x <= button.Parent.Width)
&& (y >= 0 && y <= button.Parent.Height);
button.Enabled = false;
if (moved && inParentControl)
button.Location = new Point(x - button.Size.Width / 2, y - button.Size.Height / 2);
button.Enabled = true;
}
private void button_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
MessageBox.Show(button.Name);
}
private void MouseDownMoveResizeEvent(object sender, MouseEventArgs e)
{
mouse_clicked = true;
BeforeLocation = (sender as Control).Location;
}
private void MouseUpMoveResizeEvent(object sender, MouseEventArgs e)
{
mouse_clicked = false;
}
private void MouseMoveResizeEvent(object sender, MouseEventArgs e)
{
if (mouse_clicked)
{
Panel tmp_panel = new Panel();
switch ((sender as PictureBox).Name)
{
case "pictureBox1":
//tmp_panel = panel1;
break;
case "pictureBox2":
//tmp_panel = panel2;
break;
}
tmp_panel.Height = (sender as PictureBox).Top + e.Y;
tmp_panel.Width = (sender as PictureBox).Left + e.X;
}
}
private void MouseMoveMoveEvent(object sender, MouseEventArgs e)
{
if (mouse_clicked)
{
Control c = (Control)sender;
Control p = (Control)c.Parent;
int x = c.Location.X + e.X - c.Size.Width / 2;
int y = c.Location.Y + e.Y - c.Size.Height / 2;
int x_overide = p.ClientSize.Width - c.Size.Width;
int y_overide = p.ClientSize.Height - c.Size.Height;
if (x < 0)
x = 0;
else if (x > x_overide)
x = x_overide;
if (y < 0)
y = 0;
else if (y > y_overide)
y = y_overide;
c.Location = AfterLocation = new Point(x, y);
if (BeforeLocation != AfterLocation)
{
moved = true;
}
}
}
}
}
Form1.Designer.cs
namespace ScalableForm
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMoveResizeEvent);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMoveMoveEvent);
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMoveResizeEvent);
//
// button2
//
this.button2.Location = new System.Drawing.Point(12, 41);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.Location = new System.Drawing.Point(12, 87);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 23);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// button3
//
this.button3.Location = new System.Drawing.Point(78, 39);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 0;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button_Click);
this.button3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMoveResizeEvent);
this.button3.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMoveMoveEvent);
this.button3.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMoveResizeEvent);
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.button3);
this.panel1.Controls.Add(this.maskedTextBox1);
this.panel1.Controls.Add(this.radioButton1);
this.panel1.Location = new System.Drawing.Point(15, 146);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 3;
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMoveResizeEvent);
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMoveMoveEvent);
this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMoveResizeEvent);
//
// maskedTextBox1
//
this.maskedTextBox1.Location = new System.Drawing.Point(15, 13);
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.Size = new System.Drawing.Size(100, 20);
this.maskedTextBox1.TabIndex = 6;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(12, 68);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(85, 17);
this.radioButton1.TabIndex = 5;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "radioButton1";
this.radioButton1.UseVisualStyleBackColor = true;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(150, 12);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(93, 64);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(100, 23);
this.progressBar1.TabIndex = 7;
this.progressBar1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownMoveResizeEvent);
this.progressBar1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMoveMoveEvent);
this.progressBar1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpMoveResizeEvent);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(72, 93);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 8;
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(3, 38);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(120, 20);
this.numericUpDown1.TabIndex = 9;
//
// splitContainer1
//
this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.splitContainer1.Location = new System.Drawing.Point(15, 252);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.numericUpDown1);
this.splitContainer1.Size = new System.Drawing.Size(255, 165);
this.splitContainer1.SplitterDistance = 127;
this.splitContainer1.TabIndex = 10;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 444);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Resize += new System.EventHandler(this.Form1_Resize);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.MaskedTextBox maskedTextBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.SplitContainer splitContainer1;
}
}