你有种再说一遍 发表于 2024-10-31 16:06:45

本帖最后由 你有种再说一遍 于 2024-10-31 21:01 编辑

tender138 发表于 2024-10-31 10:49
谢谢!修改以下红色代码可以返回值,但是窗口设计值,非修改后的值

Form是异步的,Lisp是同步的,
只能LispFunc上面Get其中一个字段,来包装返回

public class Class1 {
Form _form = null;


static public void RunForm() {
    _form = new();
    _form.Show();
    new Thread(()=>{
      int a = 0;
      while(true)
         _form.TextBox1.Text = a++;
    }).Start();
}


public static ResultBuffer GetFormValue(ResultBuffer resBufIn) {
    return new ResultBuffer(new TypedValue((int)LispDataType.Int32, _form.TextBox1.Text));
}


public static ResultBuffer PutFormValue(ResultBuffer resBufIn) {
    _form.Invoke(()=>{
      TextBox1.Text = resBufIn.ToString();
    });
    return true;
}
}

tender138 发表于 2024-10-31 20:48:10

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;
    }
}

tender138 发表于 2024-10-31 20:50:56

你有种再说一遍 发表于 2024-10-31 16:06
Form是异步的,Lisp是同步的,
只能LispFunc上面Get其中一个字段,来包装返回



非常感谢!具体怎么修改呢

你有种再说一遍 发表于 2024-10-31 21:01:10

tender138 发表于 2024-10-31 20:50
非常感谢!具体怎么修改呢

加一个invoke而已,修改原帖了.

yshf 发表于 2024-10-31 22:15:06

LispFunction改为如下一试:
      
      public static ResultBuffer GetVal(ResultBuffer resBufIn)
      {
            FormMain MyForm = new FormMain();
            MyForm.TextBox1.Text = "001";
            MyForm.TextBox2.Text = "002";
            Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(MyForm);
            return new ResultBuffer(new TypedValue((int)LispDataType.Text, MyForm.TextBox1.Text),
                                    new TypedValue((int)LispDataType.Text, MyForm.TextBox2.Text)
                                 );
      }

tender138 发表于 2024-11-2 16:38:40

本帖最后由 tender138 于 2024-11-2 16:40 编辑

yshf 发表于 2024-10-31 22:15
LispFunction改为如下一试:
      
      public static ResultBuffer Get ...
谢谢!我是想在非模态窗口中修改参数(不关闭窗口),然后用lisp提取窗口实时参数作图

tender138 发表于 2024-11-2 16:40:12

你有种再说一遍 发表于 2024-10-31 16:06
Form是异步的,Lisp是同步的,
只能LispFunc上面Get其中一个字段,来包装返回



多谢你的热心!因水平有限,我怎么也实现不了。
我是想在非模态窗口中修改参数(不关闭窗口),然后用lisp提取窗口实时参数作图

你有种再说一遍 发表于 2024-11-2 16:44:06

tender138 发表于 2024-11-2 16:40
多谢你的热心!因水平有限,我怎么也实现不了。
我是想在非模态窗口中修改参数(不关闭窗口),然后用li ...

先沉淀,沉淀先,总有一天你会知道的,代码就是那么普通

tender138 发表于 2024-11-2 16:56:23

你有种再说一遍 发表于 2024-11-2 16:44
先沉淀,沉淀先,总有一天你会知道的,代码就是那么普通

非常感谢!能否麻烦你在我这个基础帮忙修改?所有搜索都找遍了,还是不得要领

pxt2001 发表于 2024-11-4 13:54:37

本帖最后由 pxt2001 于 2024-11-5 08:32 编辑

楼主这个问题完全可以用Lisp+openDCl解决。
曾经我和你一样,初步接触了C#,发现轮子少,资料少,学习起来很费劲。然后lisp里面很简单的事情,在这里实现很复杂。想抄东西都没得抄。
自己在lisp需解决的问题是动态效果,是Lisp的上限在哪里。在C#解决的问题是画一条直线,C#的下限在哪里。
后面还是回到熟悉的,得心应手的lisp。捣鼓这个一般都是工程师不是程序员,只要能够解决问题就行,管他是黑猫还是白猫。
很多C#高手的确做出输入法自动切换,贴边式屏幕菜单。但极少公布源码,很可能都是一些商业秘密,也可能是程序员。
论坛C#大神,如果发布一些Lisp实现不了的程序,补充lisp的缺陷。影响会很巨大。我都嫌自己陷入Lisp是否值得,但在C#陷入更深(花费更多精力但收获不大,轮子少),工程师90%的CAD问题在Lisp能够解决。
如果你是开发天正,探索者,或者是程序员,另当别论了。欢迎大神来批判。

页: 1 [2] 3
查看完整版本: 请问Autolisp如何获取C#做的非模态界面文本框值?