| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 771 人关注过本帖
标题:C# form窗体求助
只看楼主 加入收藏
peterdane
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-3-27
收藏
 问题点数:0 回复次数:7 
C# form窗体求助

在代码的编写过程中,怎么样能够实现
在类和抽象方法中,定义了数据的计算,我想将计算的数据在窗体中输出,比如说textBox或者richtextBox
(我的意图就是,以前在代码运行中,总是用控制台程序,但是控制台程序的窗体黑乎乎的,看不请楚,我想转为用窗体输出,最好是richtextBox所以,就想将数据计算,与窗体进行数据交流,但是无法实现,请高手帮忙回答一下,问题出在那里?怎么样解决)
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Class_test
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

private System.Windows.Forms.Label label1;
public System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// 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>
public void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(8, 48);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "结果输出窗口";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(168, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

abstract class class1
{
abstract public void test();
}

class class2 : class1
{
public override void test()
{
//Console.WriteLine("class2");
//下面的代码没有办法实现,textBox后面的 text属性无法显示出来
textBox1.Text = "Convert.ToString(class2)";

}

}
class class3 : class2
{
/*public void test()
{
Console.WriteLine("class3");
}*/
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
class3 d = new class3();
d.test();
Console.Read();



}
}
}

搜索更多相关主题的帖子: form 窗体 
2006-11-05 10:20
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
textBox1.Text = "Convert.ToString(class2)"; 这里去掉引号;


static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
class3 d = new class3();
d.test();
Console.Read(); 这个也去掉
}

飘过~~
2006-11-05 10:40
peterdane
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-3-27
收藏
得分:0 

这样不行编译报错
E:\项目文件夹\Class_test\Form1.cs(100): “Class_test.Form1.textBox1”表示“字段”,此处应为“类”


class class2 : class1
{
public override void test()
{
//Console.WriteLine("class2");


//下面这个地方报错呢
textBox1.Text = Convert.ToString(class2);

}

}

在类里面没有办法调用相关的textBox1.Text这个属性

2006-11-05 10:53
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
请问你的textBox1有吗?
如果有,是不是应该写成TextBox1?

飘过~~
2006-11-05 10:54
peterdane
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-3-27
收藏
得分:0 
该窗口名称就是textBox1,自定义的是小写开头,我检查了几次都没有错啊

我很疑惑
2006-11-05 10:56
peterdane
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-3-27
收藏
得分:0 
不是吧。。。。没有人知道啊?

高手来指导指导偶啊等了一天了
2006-11-05 18:25
rainlily0315
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2005-11-19
收藏
得分:0 
什么代码这么乱。

闯出自己的天空
2006-11-06 17:00
绿竹
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-11-6
收藏
得分:0 
textBox1.Text = "Convert.ToString(class2)";
改为
textBox1.Text =class2. ToString();
另外,你没有重载ToString()
窗口的Text属性是显示名称的,你最好还是用Label或者TextBox来显示

[此贴子已经被作者于2006-11-6 18:07:34编辑过]

2006-11-06 18:03
快速回复:C# form窗体求助
数据加载中...
 
   



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

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