| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 880 人关注过本帖
标题:用c#写新建的窗体程序在vs里面可以打开运行 点击debug里面的.exe文件就不能 ...
只看楼主 加入收藏
nuduidui
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-4-10
收藏
 问题点数:0 回复次数:0 
用c#写新建的窗体程序在vs里面可以打开运行 点击debug里面的.exe文件就不能运行 只有这次不行以前都可以
后来试了一下吧 下面这行注释了 双击.exe文件就可以运行    这什么情况呀
 private ModbusTcpNet busTcpClient = new ModbusTcpNet("192.168.1.200");
我特意又写了个新的 只写这一行代码 双击.exe文件都无法运行 也不报错。
 完整测试代码如下
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HslCommunication;
using HslCommunication.ModBus;
using System.Threading;

 namespace 可能是modbustcp
{

    public partial class Form1 : Form
    {
        private ModbusTcpNet busTcpClient = new ModbusTcpNet("192.168.1.200", 502, 1);
        public Form1()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;//最大化窗体
            quanping1();  //控件随窗体全屏显示
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            busTcpClient.ConnectServer();//切换为长链接模式
            //后台线程一直读
            Thread thread = new Thread(jiankong);
            thread.IsBackground = true;
            thread.Start();

        }
        private void jiankong()
        {
            while (true)//一直读
            {
                bool coil100 = busTcpClient.ReadCoil("2048").Content; //2048=2049(m0的modbus地址)-1
                if (coil100)
                {
                    button1.BackColor = Color.Red;

                }
                else
                {
                    button1.BackColor = Color.Black;

                }
            }
        }
       //记录所以控件信息
        public void quanping1()
        {
            int count = this.Controls.Count * 2 + 2;
            float[] factor = new float[count];
            int i = 0;
            factor[i++] = Size.Width;
            factor[i++] = Size.Height;
            foreach (Control ctrl in this.Controls)
            {
                factor[i++] = ctrl.Location.X / (float)Size.Width;
                factor[i++] = ctrl.Location.Y / (float)Size.Height;
                ctrl.Tag = ctrl.Size;//!!!
            }
            Tag = factor;

        }
       //同步改变控件信息
        public void quanping2()
        {
            if (Tag != null)
            {
                float[] scale = (float[])Tag;
                int i = 2;
                foreach (Control ctrl in this.Controls)
                {
                    ctrl.Left = (int)(Size.Width * scale[i++]);
                    ctrl.Top = (int)(Size.Height * scale[i++]);
                    ctrl.Width = (int)(Size.Width / (float)scale[0] * ((Size)ctrl.Tag).Width);
                    ctrl.Height = (int)(Size.Height / (float)scale[1] * ((Size)ctrl.Tag).Height);
                }
            }
        }
        private void Form1_Resize(object sender, EventArgs e)
        {
            //控件随窗体全屏显示
            quanping2();

        }

      
    }
}

[此贴子已经被作者于2022-4-10 22:26编辑过]

搜索更多相关主题的帖子: Size ctrl float System using 
2022-04-10 22:21
快速回复:用c#写新建的窗体程序在vs里面可以打开运行 点击debug里面的.exe文件 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015345 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved