社区
C#
帖子详情
类方面的问题
cs3005
2005-08-17 09:24:44
我想写个类,改变我窗口上的控件的属性。
如何改变
...全文
79
4
打赏
收藏
类方面的问题
我想写个类,改变我窗口上的控件的属性。 如何改变
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cocainy
2005-08-17
打赏
举报
回复
using System;
using System.Windows.Forms;
namespace WindowsApp
{
/// <summary>
/// Timer 的摘要说明。
/// </summary>
public class MyTimer
{
private System.Timers.Timer theTimer;
public System.IntPtr handleTextBox;
public double Interval
{
get{return this.theTimer.Interval;}
set{this.theTimer.Interval=value;}
}
public bool Enabled
{
get{return this.theTimer.Enabled;}
set{this.theTimer.Enabled=value;}
}
public MyTimer()
{
//
// TODO: 在此处添加构造函数逻辑
//
//
//Timer
//
//
this.theTimer = new System.Timers.Timer();
this.theTimer.Interval = 1000;
this.theTimer.Enabled = false;
this.theTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.theTimer_Elapsed);
}
private void theTimer_Elapsed(object sender,System.Timers.ElapsedEventArgs e)
{
TextBox textBox = (TextBox)FrmMain.FromHandle(this.handleTextBox);
textBox.Text += e.SignalTime.ToString()+"\r\n";
//Form1.ActiveForm.Opacity = 0.50;
//Form1.ActiveForm.Top -= 10;
MessageBox.Show("时间到啦!","提醒",MessageBoxButtons.OKCancel,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
//创建一个线程
}
}
}
cocainy
2005-08-17
打赏
举报
回复
参见以下实例:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using ScheduleService;
namespace WindowsApp
{
/// <summary>
/// FrmMain 的摘要说明。
/// </summary>
public class FrmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
public System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label lblTime;
private System.Windows.Forms.Button button3;
private MyTimer theTimer ;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FrmMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.lblTime = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.theTimer = new MyTimer();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 32);
this.button1.TabIndex = 0;
this.button1.Text = "TestProcess";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(136, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 32);
this.button2.TabIndex = 1;
this.button2.Text = "TestLog";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(40, 72);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(520, 376);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// lblTime
//
this.lblTime.Location = new System.Drawing.Point(272, 16);
this.lblTime.Name = "lblTime";
this.lblTime.Size = new System.Drawing.Size(248, 23);
this.lblTime.TabIndex = 3;
//
// button3
//
this.button3.Location = new System.Drawing.Point(24, 40);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(80, 32);
this.button3.TabIndex = 4;
this.button3.Text = "Run Timer";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
//theTimer
//
this.theTimer.Enabled = false;
//
// FrmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(688, 494);
this.Controls.Add(this.button3);
this.Controls.Add(this.lblTime);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "FrmMain";
this.Text = "FrmMain";
this.Load += new System.EventHandler(this.FrmMain_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FrmMain());
}
private void button2_Click(object sender, System.EventArgs e)
{
//LogAccess.WriteLog("Test","TestButton","BeginToWrite");
lblTime.Text = DateTime.Now.ToString("yyyyMMddHHmmss");
lblTime.Text += "|"+DateTime.Now.ToString();
}
private void FrmMain_Load(object sender, System.EventArgs e)
{
//
}
private void button1_Click(object sender, System.EventArgs e)
{
ThreadManager tm=new ThreadManager();
tm.StartProcess();
}
private void button3_Click(object sender, System.EventArgs e)
{
theTimer.handleTextBox = this.textBox1.Handle;
theTimer.Interval = 2000;
theTimer.Enabled = !theTimer.Enabled;
}
}//the END of FrmMain
}//the END of NameSpace
lovewindy
2005-08-17
打赏
举报
回复
把引用传进去,然后在里面就像操作那个控件一样操作传进来的引用,要改什么样就改什么
jinjazz
2005-08-17
打赏
举报
回复
传个控件引用给你的类,然后改啊
阿里巴巴面试总结DOC版
本资源摘要信息主要总结了阿里巴巴面试中的
问题
和答案,涵盖了 Java 编程语言、设计模式、JVM 内存模型、ClassLoader 结构、UML 模型图、OSGi 框架、Spring 框架、iBatis 框架、Java 序列化、NIO 编程、HTTP 协议、...
c# 一些常用的代码还有外部浏览器操作
图片操作
方面
,C#提供了`System.Drawing`和`System.IO`命名空间来读取、修改和保存图像文件。`Image`
类
用于表示图像,`Bitmap`
类
则是最常见的图像
类
型。可以使用`Image.FromFile()`方法加载图片,然后通过`Graphics`...
testfragmentdemo
这个
问题
可能是由多种原因导致的,包括但不限于以下几个
方面
: 1. **布局
问题
**:确保在`Fragment`的布局XML文件中正确地添加了`ViewPager`。`ViewPager`需要一个父布局,如`LinearLayout`或`ConstraintLayout`,并...
Java程序设计技巧1001例
通过这1001个实例,我们可以系统地掌握Java语言的各个
方面
,包括基础语法、面向对象编程、异常处理、集合框架、多线程、输入输出流、网络编程以及Java API的使用等。 1. **基础语法**:Java的基础语法是学习的起点...
Qt 一去丶二三里 Blog(二)
同时,Qt的国际化和本地化功能使得开发全球化应用变得简单,QTranslator和QLocale
类
帮助开发者轻松处理不同语言和文化的显示
问题
。 总而言之,这篇“Qt 一去丶二三里 Blog(二)”的PDF文档可能涵盖了Qt库的多个...
C#
111,092
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章