请问Autolisp如何获取C#做的非模态界面文本框值?
请问Autolisp如何获取C#做的非模态界面文本框值?yshf 发表于 2024-10-31 15:34
不贴出窗体代码,不好判断
非常感谢兄弟一再指导,麻烦帮我修改一下,谢谢!
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Autodesk.AutoCAD.DatabaseServices;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace ModelessDlg
{
public class Class1
{
static public void LoadWin()
{
FormMain MyForm = new FormMain();
MyForm.Show();
MyForm.TextBox1.Text = "001";
MyForm.TextBox2.Text = "002";
}
public static ResultBuffer GetVal(ResultBuffer resBufIn)
{
FormMain MyForm = new FormMain();
return new ResultBuffer(new TypedValue((int)LispDataType.Int32, MyForm.TextBox1.Text));
}
}
}
namespace ModelessDlg
{
partial class FormMain
{
/// <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.TextBox1 = new System.Windows.Forms.TextBox();
this.TextBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// TextBox1
//
this.TextBox1.Location = new System.Drawing.Point(99, 12);
this.TextBox1.Name = "TextBox1";
this.TextBox1.Size = new System.Drawing.Size(100, 21);
this.TextBox1.TabIndex = 0;
this.TextBox1.Text = "123";
//
// TextBox2
//
this.TextBox2.Location = new System.Drawing.Point(99, 60);
this.TextBox2.Name = "TextBox2";
this.TextBox2.Size = new System.Drawing.Size(100, 21);
this.TextBox2.TabIndex = 1;
this.TextBox2.Text = "456";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(37, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 12);
this.label1.TabIndex = 2;
this.label1.Text = "长度";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(37, 60);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 12);
this.label2.TabIndex = 3;
this.label2.Text = "宽度";
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(230, 93);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.TextBox2);
this.Controls.Add(this.TextBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormMain";
this.Text = "参数";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.TextBox TextBox1;
public System.Windows.Forms.TextBox TextBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}
d1742647821 发表于 2024-10-30 23:30
那么你应该知道,函数打上可以用命令触发,那么函数打上特性则可以被lisp ...
非常感谢!如下代码不成功,望指教,谢谢!
namespace ModelessDlg
{
public class Class1
{
static public void LoadWin()
{
FormMain MyForm = new FormMain();
MyForm.Show();
MyForm.TextBox1.Text = "001";
MyForm.TextBox2.Text = "002";
}
public static string Getvalue()
{
FormMain MyForm = new FormMain();
string str = MyForm.TextBox1.Text;
return str;
}
}
} 本帖最后由 tender138 于 2024-10-31 10:51 编辑
yshf 发表于 2024-10-31 10:21
C#定义一个带窗体的LispFunction,然后用Lisp调用,如下 图
谢谢!修改以下红色代码可以返回值,但是窗口设计值,非修改后的值
namespace ModelessDlg
{
public class Class1
{
static public void LoadWin()
{
FormMain MyForm = new FormMain();
MyForm.Show();
MyForm.TextBox1.Text = "001";
MyForm.TextBox2.Text = "002";
}
public static ResultBuffer GetVal(ResultBuffer resBufIn)
{
FormMain MyForm = new FormMain();
return new ResultBuffer(new TypedValue((int)LispDataType.Int32, MyForm.TextBox1.Text));
}
}
} 不如把dll发出来玩玩 让写窗体的人给你留个接口 d1742647821 发表于 2024-10-29 14:34
让写窗体的人给你留个接口
谢谢!窗口是我做的,怎么留?刚接触C#,啥都不懂 窗口对象里写一个方法能返回文本的内容,如getText,并把窗口的实例存为一个静态变量,如 obj,再写一个方法调用obj.getText(),这个方法需要用lispfunction包装起来 tender138 发表于 2024-10-29 14:43
谢谢!窗口是我做的,怎么留?刚接触C#,啥都不懂
那么你应该知道,函数打上可以用命令触发,那么函数打上特性则可以被lisp调用 C#定义一个带窗体的LispFunction,然后用Lisp调用,如下 图 ...非修改后的值
不贴出窗体代码,不好判断