110,538
社区成员
发帖
与我相关
我的任务
分享
this.StartPosition = FormStartPosition.Manual;
Screen[] screens = System.Windows.Forms.Screen.AllScreens;
if (screens.Length >= 2)
{
for (int i = 0; i < screens.Length; i++)
{
//获取扩展屏
Screen childerScreen = screens[i];
this.Width = childerScreen.Bounds.Width;
this.Height = childerScreen.Bounds.Height;
this.Location = childerScreen.WorkingArea.Location;
}
}
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 测试集合
{
public partial class Forms1 : Form
{
public Dictionary<string,string> baseText { get; set; }
public event EventHandler ReSetTxt;
public Forms1()
{
InitializeComponent();
}
public void Reset()
{
foreach (Control item in this.Controls)
{
Reset(item);
}
}
private void Reset(Control con)
{
if (baseText.ContainsKey(con.Name))
{
con.Text = baseText[con.Name];
}
if (!con.HasChildren)
{
return;
}
foreach (Control c in con.Controls)
{
if (baseText.ContainsKey(c.Name))
{
c.Text = baseText[c.Name];
}
if (c.HasChildren)
{
Reset(c);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Set();
Reset();
ReSetTxt(sender, e);
}
private void Set()
{
foreach (Control item in this.Controls)
{
Set(item);
}
}
private void Set(Control con)
{
if (baseText.ContainsKey(con.Name))
{
baseText[con.Name] = con.Text;
}
else
{
baseText.Add(con.Name, con.Text);
}
if (!con.HasChildren)
{
return;
}
foreach (Control c in con.Controls)
{
if (baseText.ContainsKey(c.Name))
{
baseText[c.Name] = c.Text;
}
else
{
baseText.Add(c.Name, c.Text);
}
if (c.HasChildren)
{
Set(c);
}
}
}
}
}
namespace 测试集合
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(362, 222);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(117, 23);
this.button1.TabIndex = 0;
this.button1.Text = "新增一个窗体";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 17);
this.label1.TabIndex = 1;
this.label1.Text = "联动窗体测试程序";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(491, 257);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
}
}
Form1.cs
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 测试集合
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Dictionary<string, string> lsttxt = new Dictionary<string, string>();
private void button1_Click(object sender, EventArgs e)
{
Forms1 f = new Forms1();
f.baseText = lsttxt;
string guid = Guid.NewGuid().ToString();
f.Tag = guid;
f.ReSetTxt += (fs,fe)=>{
Control c = (Control)fs;
Forms1 fs1 = new Forms1();
while (c.Parent!=null)
{
c = c.Parent;
}
fs1 = (Forms1)c;
Dictionary<string, string> basetext=new Dictionary<string,string>();
foreach (Form item in Application.OpenForms)
{
if (item.Tag != null && fs1.Tag.ToString() == item.Tag.ToString())
{
basetext = ((Forms1)item).baseText;
}
}
foreach (Form item in Application.OpenForms)
{
if (item.Tag != null && fs1.Tag.ToString() != item.Tag.ToString())
{
Forms1 f1 = (Forms1)item;
f1.baseText = basetext;
f1.Reset();
}
}
};
f.Show();
}
}
}