-
C# 使用虚方法实现用户登录
C# 使用虚方法实现用户登录,这里需要创建密封类, 密封并重写基类中的Login方法,然后再编写处理函数完成以下代码:
myClass2 myclass2 = new myClass2(); //实例化密封类对象
Console.Write("请输入用户名:");
myclass2.Name = Console.ReadLine(); //为密封类中的用户姓名赋值
Console.Write("请输入密码:");
myclass2.Pwd = Console.ReadLine();//为密封类中的用户密码赋值
myclass2.Login();//调用密封类中的密封方法
- 2022-02-25 18:17:12下载
- 积分:1
-
C# 使用IPEndPoint类获取终结点的IP地址和端口号
Visual C# UseIPEndPoint例子,使用IPEndPoint类对象获取终结点的IP地址和端口号,运行生成的Exe文件,得到的结果如图所示:
以下是实现本功能的关键代码:
先实例化IPEndPoint类对象:
IPEndPoint IPEPoint = new IPEndPoint(IPAddress.Parse(textBox1.Text), 80);
//使用IPEndPoint类对象获取终结点的IP地址和端口号
label2.Text = "IP地址:"+IPEPoint.Address.ToString() + "
端口号:" + IPEPoint.Port;
- 2022-01-28 05:14:25下载
- 积分:1
-
C# 在Vista、Win7中显示XP风格的文件对话框
C#自定义打开文件对话框,并在文件打开对话框中添加自定义区域,可以在非Windows XP系统中调用XP风格的对话框,比如本例子演示了在Vista或Windows7 中显示XP风格的文件对话框:
private void button1_Click(object sender, EventArgs e)
{//在文件打开对话框中添加自定义区域
this.openFileDialog1.AutoUpgradeEnabled = true;
this.openFileDialog1.CustomPlaces.Add(@"F:");
this.openFileDialog1.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{//在Vista中显示XP风格的文件对话框
this.openFileDialog1.AutoUpgradeEnabled = false;
this.openFileDialog1.ShowDialog();
}
- 2022-03-15 22:57:57下载
- 积分:1
-
C# 在LINQ to DataSet中对分组操作执行子查询
C# 在LINQ to DataSet中对分组操作执行子查询,相关代码:
private void button1_Click(object sender, EventArgs e)
{//在LINQ to DataSet中对分组操作执行子查询
SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("Select * From Orders ", MyConnection);
DataSet MySet = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);
MyAdapter.Fill(MySet);
DataTable MyQueryTable = MySet.Tables[0];
var MyQuery = from MyOrder in MyQueryTable.AsEnumerable()
orderby MyOrder.Field("ShipCity")
group MyOrder by MyOrder.Field("ShipCity") into g
select new
{
MyCity = g.Key,
MyMaxFreight = (from MyData in g select MyData.Field("Freight")).Max()
- 2022-01-27 20:20:32下载
- 积分:1
-
C# 获取本地打印服务器后台文件的路径
Visual C# MyWinWPF.rar,核心代码分享如下:
private void button1_Click(object sender, RoutedEventArgs e)
{//获取本地打印服务器后台文件的路径
var MyPrintServer = new System.Printing.LocalPrintServer();
string MyInfo = "本地打印服务器后台文件的路径是:" + MyPrintServer.DefaultSpoolDirectory;
MessageBox.Show(MyInfo, "信息提示", MessageBoxButton.OK);
}
- 2022-01-23 11:13:33下载
- 积分:1
-
几个C# 窗口标题栏 按钮 任务栏自定义实例
本源码主要是收集的几个C# 窗口标题栏 按钮 任务栏自定义实例,比如隐藏和显示标题栏、允许和禁止在窗口任务栏显示程序图标等,帮助C#初学者了解一些基础的C#窗口操作知识,有很好的学习参考价值。
private void button1_Click(object sender, RoutedEventArgs e)
{//隐藏标题栏
this.WindowStyle = System.Windows.WindowStyle.None;
}
private void button2_Click(object sender, RoutedEventArgs e)
{//显示标题栏
this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
}
private void button3_Click(object sender, RoutedEventArgs e)
{//禁止在任务栏上显示程序按钮
this.ShowInTaskbar = false;
}
private void button4_Click(object sender, RoutedEventArgs e)
{//允许在任务栏上显示程序按钮
this.ShowInTaskbar = true;
}
如下图所示,点击对应的按钮,可演示对应的功能。
- 2023-03-24 21:30:03下载
- 积分:1
-
C# 实现凹凸按钮(立体按钮效果)
Visual C# 实现凹凸按钮(立体按钮效果),鼠标放在按钮上,按下鼠标左键,即可看到凹凸效果:
private void Window_Loaded(object sender, RoutedEventArgs e)
{//(上凸效果)
BevelBitmapEffect MyBevelEffect = new BevelBitmapEffect();
MyBevelEffect.BevelWidth = 20;
MyBevelEffect.EdgeProfile = EdgeProfile.CurvedIn;
MyBevelEffect.LightAngle = 320;
MyBevelEffect.Relief = 0.4;
MyBevelEffect.Smoothness = 0.4;
this.button1.BitmapEffect = MyBevelEffect;
bShift = true;
}
private void button1_Click(object sender, RoutedEventArgs e)
{//凹凸显示按钮(下凸效果)
if (bShift)
{
BevelBitmapEffect MyBevelEffect = new BevelBitmapEffect();
MyBevelEffect.BevelWidth = 20;
this.button1.BitmapEffect = MyBevelEffect;
bShift = false;
}
else
{
BevelBitmapEffect MyBevelEffect = new BevelBitmapEffect();
MyBevelEffect.BevelWidth = 20;
MyBevelEffect.EdgeProfile = EdgeProfile.CurvedIn;
MyBevelEffect.Ligh
- 2022-04-20 03:11:38下载
- 积分:1
-
C# treeView节点动态删除和添加示例
C# treeView节点动态删除和添加示例,本源码演示了创建一个treeView父节点,创建了三个子节点,然后演示了将这3个子节点添加到父节点中,最后演示了使用Remove方法移除指定的TreeView节点项,添加节点和删除节点定义了两个按钮事件,用户通过单击按钮,激活事件,两个事件的编写方法如下:
private void Form1_Load(object sender, EventArgs e)
{
//建立一个父节点
TreeNode tn1 = treeView1.Nodes.Add("名称");
//建立3个子节点
TreeNode Ntn1 = new TreeNode("明日科技");
TreeNode Ntn2 = new TreeNode("C#编程词典");
TreeNode Ntn3 = new TreeNode("C#从基础到项目实战");
//将这3个子节点添加到父节点中
tn1.Nodes.Add(Ntn1);
tn1.Nodes.Add(Ntn2);
tn1.Nodes.Add(Ntn3);
}
private void button1_Click(object sender, EventArgs e)
{
//如果用户选择了“名称”证明没有选择要删除的子节点
if (treeView1.SelectedNode.Text == "名称")
{
MessageBox.Show("请选择要删除的子节点"); //弹出选择删除节点的提示
}
else
{
treeView1.Nodes.Remove(treeView1.SelectedNode);//使用Remove方法移除选择项
}
}
- 2023-07-29 02:55:08下载
- 积分:1
-
程序守护(进程守护)-源代码C#
程序守护(进程守护)-源代码C#
/*
* 由SharpDevelop创建。
* 用户: zhang
* 日期: 2017/3/18
* 时间: 21:50
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace CPinfoSafe
{
public sealed class NotificationIcon
{
private NotifyIcon notifyIcon;
private ContextMenu notificationMenu;
DialogResult dr;
#region Initialize icon and menu
public NotificationIcon()
{
notifyIcon = new NotifyIcon();
notificationMenu = new ContextMenu(InitializeMenu());
notifyIcon.DoubleClick += IconDoubleClick;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon));
notifyIcon.Icon = (Icon)resources.Get
- 2022-11-01 19:35:03下载
- 积分:1
-
C# 使用Graphics对象在程序运行时创建位图
C# 在程序运行时创建位图,本源码实例主要是学习使用使用Graphics对象创建简单图像的例子,本程序将生成一条曲线图像,参照如下代码:
{//在程序运行时创建位图
int MyWidth=this.pictureBox1.Width;
int MyHeight=this.pictureBox1.Height;
Bitmap MyBitmap = new Bitmap(MyWidth,MyHeight);
Graphics MyGraphics = Graphics.FromImage(MyBitmap);
Pen MyPen = new Pen(Color.Black, 3);
Point[] MyPoints = { new Point(50, 100), new Point(100, 10), new Point(150, 290), new Point(200, 100), new Point(250, 10), new Point(300, 290), new Point(350, 100) };
MyGraphics.Clear(Color.White);
MyGraphics.DrawBeziers(MyPen, MyPoints);
pictureBox1.Image = MyBitmap;
- 2022-03-25 22:38:21下载
- 积分:1