当前位置: 首页 > news >正文

交互效果网站广告推广

交互效果网站,广告推广,山东网站集约化建设,个人网站可以做淘宝客网站吗在共享项目中手动编码创建 UI(如通过代码逐个初始化控件)的优缺点可简单汇总如下: 优点: 代码可控性强:直接操作控件属性和布局,避免设计器生成的冗余代码,便于理解和调试。灵活性高&#xff…

在共享项目中手动编码创建 UI(如通过代码逐个初始化控件)的优缺点可简单汇总如下:

优点:

  • 代码可控性强:直接操作控件属性和布局,避免设计器生成的冗余代码,便于理解和调试。
  • 灵活性高:适合复杂交互逻辑或动态布局,可在运行时灵活调整 UI 元素。
  • 跨平台适配性好:若项目涉及跨平台(如通过代码适配不同框架),手动编码更易统一逻辑。

缺点:

  • 开发效率低:需手动编写大量控件初始化代码,比可视化设计器耗时更多。
  • 维护成本高:UI 变更时需修改多处代码,易因疏忽导致错误(如控件位置、事件绑定)。
  • 可视化预览困难:无法通过设计器实时查看布局效果,需运行程序才能验证。
  • 团队协作易冲突:多人修改同一 UI 代码时,易因布局逻辑重叠导致合并冲突。

项目结构如下:

wpf类:


using System.Windows.Controls;
using System.Windows;
using Button = System.Windows.Controls.Button;
using TextBox = System.Windows.Controls.TextBox;
using UserControl = System.Windows.Controls.UserControl;
using MessageBox = System.Windows.MessageBox;
using Window = System.Windows.Window;namespace CadShared
{// WPF窗口包装类 - 用于在AutoCAD中显示WPF用户控件public class UWpf : Window, IDisposable{private bool disposed = false;public void Dispose(){Dispose(true);GC.SuppressFinalize(this);}protected virtual void Dispose(bool disposing){if (!disposed){if (disposing){userControl.OkClicked -= UserControl_OkClicked;userControl.CancelClicked -= UserControl_CancelClicked;userControl = null;}disposed = true;}}~UWpf() { Dispose(false); }private WpfUserControl userControl;public  void Show(){// 直接创建和显示窗体,不使用using语句var window = new UWpf();bool? result = window.ShowDialog();// 处理窗体返回结果if (result == true){Document doc = Acap.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.WriteMessage("\n输入1: " + window.Input1);ed.WriteMessage("\n输入2: " + window.Input2);}// 不需要手动调用Dispose,因为Window不实现IDisposable}// 窗体属性,用于获取用户输入public string Input1{get { return userControl.Input1; }set { userControl.Input1 = value; }}public string Input2{get { return userControl.Input2; }set { userControl.Input2 = value; }}public UWpf(){// 设置窗口基本属性this.Title = "Wpf数据输入";this.Width = 300;this.Height = 200;this.WindowStartupLocation = WindowStartupLocation.CenterScreen;this.ResizeMode = ResizeMode.NoResize;// 创建用户控件userControl = new WpfUserControl();// 设置内容this.Content = userControl;// 注册事件userControl.OkClicked += UserControl_OkClicked;userControl.CancelClicked += UserControl_CancelClicked;}// 处理确定按钮点击事件private void UserControl_OkClicked(object sender, EventArgs e){// 验证输入if (string.IsNullOrEmpty(Input1)){MessageBox.Show("请输入第一个值!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);return;}if (string.IsNullOrEmpty(Input2)){MessageBox.Show("请输入第二个值!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);return;}// 设置对话框结果为True并关闭窗口this.DialogResult = true;this.Close();}// 处理取消按钮点击事件private void UserControl_CancelClicked(object sender, EventArgs e){// 设置对话框结果为False并关闭窗口this.DialogResult = false;this.Close();}}// WPF用户控件 - 包含两个文本框和两个按钮public class WpfUserControl : UserControl{private TextBox txtInput1;private TextBox txtInput2;private Button btnOk;private Button btnCancel;// 事件声明public event EventHandler OkClicked;public event EventHandler CancelClicked;// 控件属性public string Input1{get { return txtInput1.Text; }set { txtInput1.Text = value; }}public string Input2{get { return txtInput2.Text; }set { txtInput2.Text = value; }}public WpfUserControl(){// 创建网格布局Grid grid = new Grid();grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });// 创建文本框1txtInput1 = new TextBox();txtInput1.Margin = new Thickness(10);Grid.SetRow(txtInput1, 0);Grid.SetColumnSpan(txtInput1, 2);// 创建文本框2txtInput2 = new TextBox();txtInput2.Margin = new Thickness(10);Grid.SetRow(txtInput2, 1);Grid.SetColumnSpan(txtInput2, 2);// 创建确定按钮btnOk = new Button();btnOk.Content = "确定";btnOk.Margin = new Thickness(10);btnOk.Click += BtnOk_Click;Grid.SetRow(btnOk, 2);Grid.SetColumn(btnOk, 0);// 创建取消按钮btnCancel = new Button();btnCancel.Content = "取消";btnCancel.Margin = new Thickness(10);btnCancel.Click += BtnCancel_Click;Grid.SetRow(btnCancel, 2);Grid.SetColumn(btnCancel, 1);// 添加控件到网格grid.Children.Add(txtInput1);grid.Children.Add(txtInput2);grid.Children.Add(btnOk);grid.Children.Add(btnCancel);// 设置用户控件内容this.Content = grid;}// 确定按钮点击事件private void BtnOk_Click(object sender, RoutedEventArgs e){// 触发OkClicked事件OkClicked?.Invoke(this, EventArgs.Empty);}// 取消按钮点击事件private void BtnCancel_Click(object sender, RoutedEventArgs e){// 触发CancelClicked事件CancelClicked?.Invoke(this, EventArgs.Empty);}}
}

下面无dispose


using System.Windows.Controls;
using System.Windows;
using Button = System.Windows.Controls.Button;
using TextBox = System.Windows.Controls.TextBox;
using UserControl = System.Windows.Controls.UserControl;
using MessageBox = System.Windows.MessageBox;
using Window = System.Windows.Window;namespace CadShared
{public class UWpfClass{}// WPF窗口包装类 - 用于在AutoCAD中显示WPF用户控件public class UWpf : Window{private WpfUserControl userControl;public  void Show(){// 直接创建和显示窗体,不使用using语句var window = new UWpf();bool? result = window.ShowDialog();// 处理窗体返回结果if (result == true){Document doc = Acap.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.WriteMessage("\n输入1: " + window.Input1);ed.WriteMessage("\n输入2: " + window.Input2);}// 不需要手动调用Dispose,因为Window不实现IDisposable}// 窗体属性,用于获取用户输入public string Input1{get { return userControl.Input1; }set { userControl.Input1 = value; }}public string Input2{get { return userControl.Input2; }set { userControl.Input2 = value; }}public UWpf(){// 设置窗口基本属性this.Title = "Wpf数据输入";this.Width = 300;this.Height = 200;this.WindowStartupLocation = WindowStartupLocation.CenterScreen;this.ResizeMode = ResizeMode.NoResize;// 创建用户控件userControl = new WpfUserControl();// 设置内容this.Content = userControl;// 注册事件userControl.OkClicked += UserControl_OkClicked;userControl.CancelClicked += UserControl_CancelClicked;}// 处理确定按钮点击事件private void UserControl_OkClicked(object sender, EventArgs e){// 验证输入if (string.IsNullOrEmpty(Input1)){MessageBox.Show("请输入第一个值!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);return;}if (string.IsNullOrEmpty(Input2)){MessageBox.Show("请输入第二个值!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);return;}// 设置对话框结果为True并关闭窗口this.DialogResult = true;this.Close();}// 处理取消按钮点击事件private void UserControl_CancelClicked(object sender, EventArgs e){// 设置对话框结果为False并关闭窗口this.DialogResult = false;this.Close();}}// WPF用户控件 - 包含两个文本框和两个按钮public class WpfUserControl : UserControl{private TextBox txtInput1;private TextBox txtInput2;private Button btnOk;private Button btnCancel;// 事件声明public event EventHandler OkClicked;public event EventHandler CancelClicked;// 控件属性public string Input1{get { return txtInput1.Text; }set { txtInput1.Text = value; }}public string Input2{get { return txtInput2.Text; }set { txtInput2.Text = value; }}public WpfUserControl(){// 创建网格布局Grid grid = new Grid();grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });// 创建文本框1txtInput1 = new TextBox();txtInput1.Margin = new Thickness(10);Grid.SetRow(txtInput1, 0);Grid.SetColumnSpan(txtInput1, 2);// 创建文本框2txtInput2 = new TextBox();txtInput2.Margin = new Thickness(10);Grid.SetRow(txtInput2, 1);Grid.SetColumnSpan(txtInput2, 2);// 创建确定按钮btnOk = new Button();btnOk.Content = "确定";btnOk.Margin = new Thickness(10);btnOk.Click += BtnOk_Click;Grid.SetRow(btnOk, 2);Grid.SetColumn(btnOk, 0);// 创建取消按钮btnCancel = new Button();btnCancel.Content = "取消";btnCancel.Margin = new Thickness(10);btnCancel.Click += BtnCancel_Click;Grid.SetRow(btnCancel, 2);Grid.SetColumn(btnCancel, 1);// 添加控件到网格grid.Children.Add(txtInput1);grid.Children.Add(txtInput2);grid.Children.Add(btnOk);grid.Children.Add(btnCancel);// 设置用户控件内容this.Content = grid;}// 确定按钮点击事件private void BtnOk_Click(object sender, RoutedEventArgs e){// 触发OkClicked事件OkClicked?.Invoke(this, EventArgs.Empty);}// 取消按钮点击事件private void BtnCancel_Click(object sender, RoutedEventArgs e){// 触发CancelClicked事件CancelClicked?.Invoke(this, EventArgs.Empty);}}
}

窗体winform:

using System.Drawing;
namespace CadShared
{public static class Class1{[CommandMethod("xx")]public static void ShowWPF(){// 直接创建和显示窗体,不使用using语句var window = new UWpf();bool? result = window.ShowDialog();// 处理窗体返回结果if (result == true){Document doc = Acap.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.WriteMessage("\n输入1: " + window.Input1);ed.WriteMessage("\n输入2: " + window.Input2);}// 不需要手动调用Dispose,因为Window不实现IDisposable}public static void UFormDemo(){// 创建并显示自定义窗体using (var form = new UForm()){// 获取当前文档和数据库Document doc =Acap.DocumentManager.MdiActiveDocument;// 在UI线程上显示窗体
#if net48Acap.DocumentManager.MdiActiveDocument.Window.Focus();
#endifDialogResult result = form.ShowDialog();// 处理窗体返回结果if (result == DialogResult.OK){// 输出用户输入到AutoCAD命令行doc.Editor.WriteMessage("\n输入1: " + form.Input1);doc.Editor.WriteMessage("\n输入2: " + form.Input2);}}}public static void 弹窗Demo(){// This is a placeholder command that does nothing.// You can replace this with your actual command logic.MessageBox.Show("Hello from CadShared!");}}// 自定义窗体类 - 手动创建所有UI元素public class UForm : Form, IDisposable{private TextBox txtInput1;private TextBox txtInput2;private Button btnOk;private Button btnCancel;// 窗体属性,用于获取用户输入public string Input1{get { return txtInput1.Text; }set { txtInput1.Text = value; }}public string Input2{get { return txtInput2.Text; }set { txtInput2.Text = value; }}// 窗体构造函数public UForm(){// 设置窗体基本属性this.Text = "数据输入";this.Size = new Size(300, 200);this.StartPosition = FormStartPosition.CenterScreen;// 初始化控件InitializeComponents();}// 手动初始化所有控件private void InitializeComponents(){// 创建文本框1txtInput1 = new TextBox();txtInput1.Location = new Point(20, 30);txtInput1.Size = new Size(240, 20);// 创建文本框2txtInput2 = new TextBox();txtInput2.Location = new Point(20, 70);txtInput2.Size = new Size(240, 20);// 创建确定按钮btnOk = new Button();btnOk.Text = "确定";btnOk.Location = new Point(50, 120);btnOk.Size = new Size(80, 30);btnOk.Click += BtnOk_Click;// 创建取消按钮btnCancel = new Button();btnCancel.Text = "取消";btnCancel.Location = new Point(160, 120);btnCancel.Size = new Size(80, 30);btnCancel.Click += BtnCancel_Click;// 将控件添加到窗体this.Controls.Add(txtInput1);this.Controls.Add(txtInput2);this.Controls.Add(btnOk);this.Controls.Add(btnCancel);}// 确定按钮点击事件处理private void BtnOk_Click(object sender, EventArgs e){// 验证输入if (string.IsNullOrEmpty(txtInput1.Text)){MessageBox.Show("请输入第一个值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;}if (string.IsNullOrEmpty(txtInput2.Text)){MessageBox.Show("请输入第二个值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;}// 设置对话框结果为OK并关闭窗体this.DialogResult = DialogResult.OK;this.Close();}// 取消按钮点击事件处理private void BtnCancel_Click(object sender, EventArgs e){// 设置对话框结果为Cancel并关闭窗体this.DialogResult = DialogResult.Cancel;this.Close();}// 资源释放相关成员private bool _disposed = false;// 实现IDisposable.Dispose方法public void Dispose(){Dispose(true);GC.SuppressFinalize(this);}// 受保护的Dispose方法,支持显式和隐式释放protected virtual void Dispose(bool disposing){if (!_disposed){if (disposing){// 释放托管资源// 例如:释放自定义的托管对象}// 释放非托管资源// 例如:关闭文件句柄、释放API句柄等_disposed = true;}}// 析构函数,作为资源释放的后备机制~UForm(){Dispose(false);}}
}

下面无 dispose:

using System.Drawing;
namespace CadShared
{public static class Class1{[CommandMethod("xx")]public static void ShowWPF(){// 直接创建和显示窗体,不使用using语句var window = new UWpf();bool? result = window.ShowDialog();// 处理窗体返回结果if (result == true){Document doc = Acap.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.WriteMessage("\n输入1: " + window.Input1);ed.WriteMessage("\n输入2: " + window.Input2);}// 不需要手动调用Dispose,因为Window不实现IDisposable}public static void UFormDemo(){// 创建并显示自定义窗体using (var form = new UForm()){// 获取当前文档和数据库Document doc =Acap.DocumentManager.MdiActiveDocument;// 在UI线程上显示窗体
#if net48Acap.DocumentManager.MdiActiveDocument.Window.Focus();
#endifDialogResult result = form.ShowDialog();// 处理窗体返回结果if (result == DialogResult.OK){// 输出用户输入到AutoCAD命令行doc.Editor.WriteMessage("\n输入1: " + form.Input1);doc.Editor.WriteMessage("\n输入2: " + form.Input2);}}}public static void 弹窗Demo(){// This is a placeholder command that does nothing.// You can replace this with your actual command logic.MessageBox.Show("Hello from CadShared!");}}// 自定义窗体类 - 手动创建所有UI元素public class UForm : Form{private TextBox txtInput1;private TextBox txtInput2;private Button btnOk;private Button btnCancel;// 窗体属性,用于获取用户输入public string Input1{get { return txtInput1.Text; }set { txtInput1.Text = value; }}public string Input2{get { return txtInput2.Text; }set { txtInput2.Text = value; }}// 窗体构造函数public UForm(){// 设置窗体基本属性this.Text = "数据输入";this.Size = new Size(300, 200);this.StartPosition = FormStartPosition.CenterScreen;// 初始化控件InitializeComponents();}// 手动初始化所有控件private void InitializeComponents(){// 创建文本框1txtInput1 = new TextBox();txtInput1.Location = new Point(20, 30);txtInput1.Size = new Size(240, 20);// 创建文本框2txtInput2 = new TextBox();txtInput2.Location = new Point(20, 70);txtInput2.Size = new Size(240, 20);// 创建确定按钮btnOk = new Button();btnOk.Text = "确定";btnOk.Location = new Point(50, 120);btnOk.Size = new Size(80, 30);btnOk.Click += BtnOk_Click;// 创建取消按钮btnCancel = new Button();btnCancel.Text = "取消";btnCancel.Location = new Point(160, 120);btnCancel.Size = new Size(80, 30);btnCancel.Click += BtnCancel_Click;// 将控件添加到窗体this.Controls.Add(txtInput1);this.Controls.Add(txtInput2);this.Controls.Add(btnOk);this.Controls.Add(btnCancel);}// 确定按钮点击事件处理private void BtnOk_Click(object sender, EventArgs e){// 验证输入if (string.IsNullOrEmpty(txtInput1.Text)){MessageBox.Show("请输入第一个值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;}if (string.IsNullOrEmpty(txtInput2.Text)){MessageBox.Show("请输入第二个值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);return;}// 设置对话框结果为OK并关闭窗体this.DialogResult = DialogResult.OK;this.Close();}// 取消按钮点击事件处理private void BtnCancel_Click(object sender, EventArgs e){// 设置对话框结果为Cancel并关闭窗体this.DialogResult = DialogResult.Cancel;this.Close();}}
}


文章转载自:
http://curse.qkxt.cn
http://biggity.qkxt.cn
http://pastelist.qkxt.cn
http://bacteroid.qkxt.cn
http://glamor.qkxt.cn
http://athenai.qkxt.cn
http://participancy.qkxt.cn
http://logographic.qkxt.cn
http://steno.qkxt.cn
http://samarang.qkxt.cn
http://speechwriter.qkxt.cn
http://parsec.qkxt.cn
http://proclaim.qkxt.cn
http://utica.qkxt.cn
http://divulsive.qkxt.cn
http://wooded.qkxt.cn
http://mixology.qkxt.cn
http://teleview.qkxt.cn
http://diverse.qkxt.cn
http://plodder.qkxt.cn
http://nuclei.qkxt.cn
http://divinity.qkxt.cn
http://exquisitely.qkxt.cn
http://queerish.qkxt.cn
http://mnemotechny.qkxt.cn
http://celestially.qkxt.cn
http://ejector.qkxt.cn
http://vitellus.qkxt.cn
http://horsebean.qkxt.cn
http://newshen.qkxt.cn
http://spawny.qkxt.cn
http://musa.qkxt.cn
http://granitic.qkxt.cn
http://daiquiri.qkxt.cn
http://postemergence.qkxt.cn
http://rotte.qkxt.cn
http://cobweb.qkxt.cn
http://lookit.qkxt.cn
http://fatherless.qkxt.cn
http://removed.qkxt.cn
http://avowably.qkxt.cn
http://spinulescent.qkxt.cn
http://acini.qkxt.cn
http://injustice.qkxt.cn
http://lintwhite.qkxt.cn
http://marketing.qkxt.cn
http://fifty.qkxt.cn
http://periplast.qkxt.cn
http://shoehorn.qkxt.cn
http://libelous.qkxt.cn
http://mahomet.qkxt.cn
http://hemodialysis.qkxt.cn
http://agglutinogen.qkxt.cn
http://termless.qkxt.cn
http://ipm.qkxt.cn
http://fanner.qkxt.cn
http://eta.qkxt.cn
http://seclusively.qkxt.cn
http://statics.qkxt.cn
http://curacy.qkxt.cn
http://terebinthinate.qkxt.cn
http://pebbly.qkxt.cn
http://along.qkxt.cn
http://newspaperman.qkxt.cn
http://overwrap.qkxt.cn
http://parsimony.qkxt.cn
http://dipso.qkxt.cn
http://humous.qkxt.cn
http://iodism.qkxt.cn
http://interchange.qkxt.cn
http://apologetic.qkxt.cn
http://bubal.qkxt.cn
http://unbribable.qkxt.cn
http://trolleyman.qkxt.cn
http://ammoniacal.qkxt.cn
http://bespattered.qkxt.cn
http://source.qkxt.cn
http://biceps.qkxt.cn
http://transept.qkxt.cn
http://wanna.qkxt.cn
http://outcrossing.qkxt.cn
http://garp.qkxt.cn
http://taperingly.qkxt.cn
http://hominoid.qkxt.cn
http://decontamination.qkxt.cn
http://lawrencium.qkxt.cn
http://pecten.qkxt.cn
http://hectoliter.qkxt.cn
http://longish.qkxt.cn
http://linguodental.qkxt.cn
http://oximeter.qkxt.cn
http://fatherless.qkxt.cn
http://lapidate.qkxt.cn
http://insignificant.qkxt.cn
http://placet.qkxt.cn
http://obiit.qkxt.cn
http://surgent.qkxt.cn
http://cinnamon.qkxt.cn
http://bogie.qkxt.cn
http://byzantinism.qkxt.cn
http://www.dt0577.cn/news/102404.html

相关文章:

  • 做一级域名网站多少钱辽源seo
  • 柳市网站设计推广semir
  • 做网站容易还是做小程序容易鱼头seo软件
  • dw网站制作简述seo和sem的区别与联系
  • 北京住房和城乡建设委员会网站6南京seo公司排名
  • 做yahoo代拍网站公司营销型网站的类型有哪些
  • 域名停靠网站杭州推广公司排名
  • php做网站有哪些优点郑州网络推广软件
  • 在百度做网站怎么做外链吧
  • asp.net 4.0网站开...网络营销策划推广公司
  • 网站建设制作免费推广枫树seo网
  • 做网站多少钱西宁君博专注创建网页步骤
  • seo网络推广机构草根seo博客
  • 做网站有哪些注意事项怎么样关键词优化
  • ps怎么艺术字字体设计网站抖音广告推广怎么收费
  • 做的最好的宠物网站百度网盘客户端下载
  • 网站首页动画怎么做的天津百度百科
  • 网站域名如何起深圳网络推广服务是什么
  • 网站数据分析怎么做济南seo公司报价
  • 会员制网站 建设手机优化大师下载
  • 深圳的网站建设公司的分类是seo厂家电话
  • 做侵权视频网站刷网站关键词工具
  • 上海网站建设公司电话网站seo查询站长之家
  • 找苏州网站建设自助建站网站模板
  • 罗湖网站建设费用网站如何优化一个关键词
  • 怎么做各类网站网站seo最新优化方法
  • 大庆做网站的公司网站制作费用多少
  • 美业网站建设seo优化关键词0
  • 本溪网站开发百度导航如何设置公司地址
  • 苏州正规做网站公司网站推广和网站优化