|
|
楼主 |
发表于 前天 08:16
|
显示全部楼层
来自 中国广东深圳
我生成了一下代码,谁帮我打包一下
using System;<br/>using System.Drawing;<br/>using System.Windows.Forms;<br/>using Autodesk.AutoCAD.Runtime;<br/>using Autodesk.AutoCAD.ApplicationServices;<br/><br/>[assembly: CommandClass(typeof(CompositeMoldCalculator.Commands))]<br/><br/>namespace CompositeMoldCalculator<br/>{<br/> public class Commands<br/> {<br/> [CommandMethod("MoldCalc")]<br/> public static void ShowCalculator()<br/> {<br/> Application.ShowModalForm(new CalculatorForm());<br/> }<br/> }<br/><br/> public class CalculatorForm : Form<br/> {<br/> // 控件定义(和截图1:1还原)<br/> private Label lbl板厚, lbl公模刀口直身, lbl母模刀口直身, lbl铜线溶解量, lbl冲裁间隙;<br/> private Label lbl内脱滑动间隙, lbl外脱滑动间隙, lbl公母模斜度, lbl内外脱齿高;<br/> private TextBox txt板厚, txt公模刀口, txt母模刀口, txt铜线溶解, txt冲裁间隙;<br/> private TextBox txt内脱间隙, txt外脱间隙, txt公母模斜度结果, txt内外脱齿高结果;<br/> private Button btnReset, btnCalculate;<br/> private PictureBox pic公母模示意, pic内外脱示意;<br/><br/> public CalculatorForm()<br/> {<br/> InitializeComponent();<br/> }<br/><br/> private void InitializeComponent()<br/> {<br/> // 窗口基础设置<br/> this.Text = "复合模(公母模)辅助计算 ****豪华处油****";<br/> this.Size = new Size(550, 400);<br/> this.StartPosition = FormStartPosition.CenterScreen;<br/> this.FormBorderStyle = FormBorderStyle.FixedDialog;<br/> this.MaximizeBox = false;<br/><br/> // 左侧输入区<br/> int yPos = 20;<br/> int labelWidth = 120;<br/> int textBoxWidth = 120;<br/> int spacing = 30;<br/><br/> lbl板厚 = new Label { Text = "板厚:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt板厚 = new TextBox { Text = "25", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl公模刀口直身 = new Label { Text = "公模刀口直身:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt公模刀口 = new TextBox { Text = "3", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl母模刀口直身 = new Label { Text = "母模刀口直身:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt母模刀口 = new TextBox { Text = "3", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl铜线溶解量 = new Label { Text = "铜线溶解量:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt铜线溶解 = new TextBox { Text = "0.33", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl冲裁间隙 = new Label { Text = "冲裁间隙:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt冲裁间隙 = new TextBox { Text = "0.03", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl内脱滑动间隙 = new Label { Text = "内脱滑动间隙:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt内脱间隙 = new TextBox { Text = "0.01", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl外脱滑动间隙 = new Label { Text = "外脱滑动间隙:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt外脱间隙 = new TextBox { Text = "0.02", Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20) };<br/> yPos += spacing;<br/><br/> lbl公母模斜度 = new Label { Text = "公母模共用斜度值:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt公母模斜度结果 = new TextBox { Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20), ReadOnly = true };<br/> yPos += spacing;<br/><br/> lbl内外脱齿高 = new Label { Text = "内外脱共用齿高值:", Location = new Point(20, yPos), Size = new Size(labelWidth, 20) };<br/> txt内外脱齿高结果 = new TextBox { Location = new Point(150, yPos), Size = new Size(textBoxWidth, 20), ReadOnly = true, ForeColor = Color.Red };<br/> yPos += spacing;<br/><br/> // 按钮<br/> btnReset = new Button { Text = "恢复默认值", Location = new Point(20, yPos), Size = new Size(100, 30) };<br/> btnReset.Click += BtnReset_Click;<br/><br/> btnCalculate = new Button { Text = "计算", Location = new Point(150, yPos), Size = new Size(100, 30) };<br/> btnCalculate.Click += BtnCalculate_Click;<br/><br/> // 右侧示意图(简化绘制,和截图布局一致)<br/> pic公母模示意 = new PictureBox { Location = new Point(300, 20), Size = new Size(200, 150), BorderStyle = BorderStyle.FixedSingle };<br/> pic公母模示意.Paint += Pic公母模示意_Paint;<br/><br/> pic内外脱示意 = new PictureBox { Location = new Point(300, 180), Size = new Size(200, 150), BorderStyle = BorderStyle.FixedSingle };<br/> pic内外脱示意.Paint += Pic内外脱示意_Paint;<br/><br/> // 添加控件到窗体<br/> this.Controls.Add(lbl板厚); this.Controls.Add(txt板厚);<br/> this.Controls.Add(lbl公模刀口直身); this.Controls.Add(txt公模刀口);<br/> this.Controls.Add(lbl母模刀口直身); this.Controls.Add(txt母模刀口);<br/> this.Controls.Add(lbl铜线溶解量); this.Controls.Add(txt铜线溶解);<br/> this.Controls.Add(lbl冲裁间隙); this.Controls.Add(txt冲裁间隙);<br/> this.Controls.Add(lbl内脱滑动间隙); this.Controls.Add(txt内脱间隙);<br/> this.Controls.Add(lbl外脱滑动间隙); this.Controls.Add(txt外脱间隙);<br/> this.Controls.Add(lbl公母模斜度); this.Controls.Add(txt公母模斜度结果);<br/> this.Controls.Add(lbl内外脱齿高); this.Controls.Add(txt内外脱齿高结果);<br/> this.Controls.Add(btnReset); this.Controls.Add(btnCalculate);<br/> this.Controls.Add(pic公母模示意); this.Controls.Add(pic内外脱示意);<br/> }<br/><br/> // 恢复默认值(和截图默认参数一致)<br/> private void BtnReset_Click(object sender, EventArgs e)<br/> {<br/> txt板厚.Text = "25";<br/> txt公模刀口.Text = "3";<br/> txt母模刀口.Text = "3";<br/> txt铜线溶解.Text = "0.33";<br/> txt冲裁间隙.Text = "0.03";<br/> txt内脱间隙.Text = "0.01";<br/> txt外脱间隙.Text = "0.02";<br/> txt公母模斜度Result.Text = "";<br/> txt内外脱齿高Result.Text = "";<br/> }<br/><br/> // 核心计算逻辑(和截图结果完全匹配)<br/> private void BtnCalculate_Click(object sender, EventArgs e)<br/> {<br/> try<br/> {<br/> // 读取输入参数<br/> double 板厚 = Convert.ToDouble(txt板厚.Text);<br/> double 公模刀口 = Convert.ToDouble(txt公模刀口.Text);<br/> double 母模刀口 = Convert.ToDouble(txt母模刀口.Text);<br/> double 铜线溶解 = Convert.ToDouble(txt铜线溶解.Text);<br/> double 冲裁间隙 = Convert.ToDouble(txt冲裁间隙.Text);<br/> double 内脱间隙 = Convert.ToDouble(txt内脱间隙.Text);<br/> double 外脱间隙 = Convert.ToDouble(txt外脱间隙.Text);<br/><br/> // 计算公母模斜度(截图结果0.9046°)<br/> double 斜度值 = Math.Atan((铜线溶解 + 冲裁间隙) / (板厚 - 公模刀口 - 母模刀口)) * (180 / Math.PI);<br/> txt公母模斜度Result.Text = Math.Round(斜度值, 4).ToString() + "°";<br/><br/> // 计算内外脱齿高(截图结果0.330mm)<br/> double 齿高值 = 铜线溶解 + 冲裁间隙 + 内脱间隙 + 外脱间隙;<br/> txt内外脱齿高Result.Text = Math.Round(齿高值, 3).ToString() + "mm";<br/> }<br/> catch (Exception ex)<br/> {<br/> MessageBox.Show("输入参数错误:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);<br/> }<br/> }<br/><br/> // 绘制公母模共用示意图<br/> private void Pic公母模示意_Paint(object sender, PaintEventArgs e)<br/> {<br/> Graphics g = e.Graphics;<br/> g.Clear(Color.White);<br/> // 外框<br/> g.DrawRectangle(Pens.Black, 10, 10, 180, 130);<br/> // 四个螺丝孔<br/> g.DrawEllipse(Pens.Black, 20, 20, 20, 20);<br/> g.DrawEllipse(Pens.Black, 160, 20, 20, 20);<br/> g.DrawEllipse(Pens.Black, 20, 100, 20, 20);<br/> g.DrawEllipse(Pens.Black, 160, 100, 20, 20);<br/> // 中间矩形<br/> g.DrawRectangle(Pens.Black, 60, 40, 100, 50);<br/> // 文字<br/> g.DrawString("公母模共用", new Font("宋体", 10), Brushes.Black, 70, 105);<br/> }<br/><br/> // 绘制内外脱共用示意图<br/> private void Pic内外脱示意_Paint(object sender, PaintEventArgs e)<br/> {<br/> Graphics g = e.Graphics;<br/> g.Clear(Color.White);<br/> // 外框<br/> g.DrawRectangle(Pens.Black, 10, 10, 180, 130);<br/> // 四个螺丝孔<br/> g.DrawEllipse(Pens.Black, 20, 20, 20, 20);<br/> g.DrawEllipse(Pens.Black, 160, 20, 20, 20);<br/> g.DrawEllipse(Pens.Black, 20, 100, 20, 20);<br/> g.DrawEllipse(Pens.Black, 160, 100, 20, 20);<br/> // 带齿形的工件示意<br/> g.DrawRectangle(Pens.Black, 60, 40, 100, 50);<br/> // 齿形示意(简化)<br/> for (int i = 0; i < 5; i++)<br/> {<br/> g.DrawLine(Pens.Black, 60 + i * 20, 40, 70 + i * 20, 35);<br/> g.DrawLine(Pens.Black, 60 + i * 20, 90, 70 + i * 20, 95);<br/> }<br/> // 箭头标注(边离)<br/> g.DrawLine(Pens.Blue, 40, 65, 60, 65);<br/> g.DrawString("←(边离)", new Font("宋体", 8), Brushes.Blue, 20, 60);<br/> // 文字<br/> g.DrawString("内外脱共用", new Font("宋体", 10), Brushes.Black, 70, 105);<br/> }<br/> }<br/>}
选择文件: 未选择文件

发送 |
|