28
2014
09

C#下对WinFrom程序进行打包

一、应用程序文件夹操作

1、新建一个安装项目,起名“测试打包”

30
2012
03

C# Winfrom中走动的时间

//Form1.cs的代码
using System.Threading;//用线程来,虽然先引进这个命名空间

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//因为VS2005有这个安全线程限制,我们先把这个限制关掉:
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
...
30
2012
03

C# Winfrom中右键的快捷菜单

从工具箱中找到ContextMenuStrip控件,将这个控件拖曳到Form或者控件的设计页面上。这时系统就会在这个页面下面自动创建一个contextMenuStrip1控件,如果你想在这个页面添加多个菜单,那么你也可以拖曳多个这种控件到设计页面上。contextMenuStrip1(非可视化控件,位于菜单和工具栏下面的ContextMenuStrip控件)然后在界面上设置你的contextMenuStrip1想写什么随便写

然后拖出一个richTextBox1设置ContextMenuStricp属性为为contextMenuStrip1。(找到richTextBox1的ContextMenuStricp属性(属性栏上有),右边的下拉按钮可以选择)。
...
30
2012
03

C# Winfrom中逆序输出数字

using System;
class Program
{
static void Main(string[] args)
{
int n;
while (!int.TryParse(Console.ReadLine(), out n))
Console.WriteLine("try again");
StringBuilder sa = new StringBuilder();
string s = n.ToString();
...
28
2012
03

C# Winfrom中获取当前日期

获取当前时间,年,月,日,小时,分,秒,还有星期几
private void Main_F_Load(object sender, EventArgs e)
{
string[] weekdays = {"星期天","星期一","星期二","星期三","星期四","星期五","星期六" };
DateTime dt = DateTime.Now;
int year = dt.Year;
int mouth = dt.Month;
int day = dt.Day;
...
28
2012
03

C# Winfrom中光标的行号和列号及光标位置

private void timer2_Tick(object sender, EventArgs e)
{
//int total = richTextBox1.GetLineFromCharIndex(richTextBox1.Text.Length) + 1;
//int total = richTextBox1.Lines.Length;//得到总行数。
int index = richTextBox1.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引!!
...
28
2012
03

C# Winfrom中遍历控件

private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
if (c.GetType().Name == "Button")
((Button)c).Click += new System.EventHandler(Button_Click);
}

private void Button_Click(object Sender, EventArgs e)
...
28
2012
03

C# Winfrom中边框样式设置

FormBorderStyle属性,表示要为窗体显示的边框样式。默认为 FormBorderStyle.Sizable。

窗体的边框样式确定窗体的外边缘如何显示。除了更改窗体的边框显示方式外,某些边框样式还阻止调整窗体的大小。例如,FormBorderStyle.FixedDialog 边框样式将窗体的边框更改为对话框的边框,并阻止调整该窗体的大小。该边框样式还可影响窗体标题栏部分的大小或可用性。

None 无边框。
FixedSingle 固定的单行边框。
Fixed3D 固定的三维边框。
...
28
2012
03

C# Winfrom中TextBox实现换行

要让一个Windows Form的TextBox显示多行文本就得把它的Multiline属性设置为true。
这个大家都知道,可是当你要在代码中为Text属性设置多行文本的时候可能会遇到点麻烦:)

你往往会想到直接付给一个含有换行符"\n"的字符串给Text属性:
aTextBox.Text = "First Line\nSecond Line\nThird Line";可是实际运行的时候你却发现它始终不会换行,显示的结果为"First LineSecond LineThirdLine"。

其实主要是因为TextBox运行在Windows上。Windows能够显示的换行必须由两个字符组成:carriage return & line feed,也就是必须是"\r\n"。如果只是"\n"在Windows中不能显示为换行的,这与Linux/Unix等其他的操作系统不一样。所以上边如果把"\n"替换成"\r\n"就可以了。"\n\n"也可以实现。
...
«1»