二二八事件 C#怎么注册ComboBox 的SelectedValueChanged 事件?求完整程式码
C#怎么注册ComboBox 的SelectedValueChanged 事件?求完整程式码
C#怎么注册ComboBox 的SelectedValueChanged 事件?求完整程式码
public Form1(){ InitializeComponent(); boBox1.SelectedIndexChanged += new EventHandler(boBox1_SelectedIndexChanged);}void boBox1_SelectedIndexChanged(object sender, EventArgs e){ 做事的程式码就写这了}c#中怎么把Combobox中选中的在label中显示出来。求完整程式码
已测试过,OK,望采纳。
private void Form1_Load(object sender, EventArgs e) { var aList = ComboBoxItem.GetList(); boBox1.DataSource = aList; boBox1.DisplayMember = "Text"; boBox1.ValueMember = "Value"; var aComboBoxItem = boBox1.SelectedItem as ComboBoxItem; if (aComboBoxItem != null) { var aValue = aComboBoxItem.Value; var aText = aComboBoxItem.Text; label1.Text = aText; } } private class ComboBoxItem { public string Value { get; set; } public string Text { get; set; } public static List<ComboBoxItem> GetList() { var aList = new List<ComboBoxItem>(); for (int i = 0; i < 10; i++) { var aComboBoxItem = new ComboBoxItem(); aComboBoxItem.Text = string.Format("Text_{0}", i); aComboBoxItem.Value = string.Format("Value_{0}", i); aList.Add(aComboBoxItem); } return aList; } }ASP+Acess怎样实现注册、登入功能?求完整的程式码!
需要?
加q
使用者名称就是
C#中将DataTable以PDF 的格式汇出!(求完整程式码)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
static DataTable datatable = new DataTable("testpdf");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataRow dr;
datatable.Columns.Add(new DataColumn("编号"));
datatable.Columns.Add(new DataColumn("使用者名称"));
for (int i = 1; i < 5; i++)
{
dr = datatable.NewRow();
dr[0] = "风过无痕";
dr[1] = "叶落无声";
datatable.Rows.Add(dr);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("111.pdf"), FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.CreateFont("C:\WINDOWS\Fonts\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontChinese = new Font(bfChinese, 12);
document.Add(new Paragraph(this.TextBox1.Text.ToString(), fontChinese));
iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance(Server.MapPath("xxx.jpg"));
document.Add(jpeg);
PdfPTable table = new PdfPTable(datatable.Columns.Count);
for (int i = 0; i < datatable.Rows.Count; i++)
{
for (int j = 0; j < datatable.Columns.Count; j++)
{
table.AddCell(new Phrase(datatable.Rows[i][j].ToString(), fontChinese));
}
}
document.Add(table);
document.Close();
}
catch (DocumentException de)
{
Response.Write(de.ToString());
}
}
}
这是转载别人的原始码
他部落格文章地址::wsxieyue.blog.163./blog/static/1286605982010217224731/
c#程式码 上传档案完整程式码
webconfig 配置
<!--档案上传型别-->
<add key="FileType" value=".doc,.xls,.txt,.rar"/>
<add key="PicTureTye" value=".jpg|.gif|.png|.bmp|.psd|.svg|"/>
<!--上传档案大小-->
<add key="FileSizeLimit" value="102400"/>
#region 判断上传档案型别
protected bool IsAllowableFileType()
{
从web.config读取判断档案型别限制
string strFileTypeLimit = ConfigurationManager.AppSettings["FileType"].ToString();
当前副档名是否包含在这个字串中
if (strFileTypeLimit.IndexOf(Path.GetExtension(FileUp.FileName).ToLower()) != -1)
{
return true;
}
else
return false;
}
protected bool IsAllowablePictureType()
{
从web.config读取判断图片型别限制
string strFileTypeLimit = ConfigurationManager.AppSettings["PicTureTye"].ToString();
当前副档名是否包含在这个字串中
if (strFileTypeLimit.IndexOf(Path.GetExtension(FileUp.FileName).ToLower()) != -1)
{
return true;
}
else
return false;
}
#endregion
#region 判断档案大小限制
private bool IsAllowableFileSize()
{
从web.config读取判断档案大小的限制
double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FileSizeLimit"]) * 1024;
判断档案是否超出了限制
if (iFileSizeLimit > FileUp.PostedFile.ContentLength)
{
return true;
}
else
{
return false;
}
}
#endregion
protected void btnUpFile_Click(object sender, EventArgs e)
{
判读是否有上传档案
if (FileUp.PostedFile.ContentLength > 0)
{
if (IsAllowableFileType())
{
if (Directory.Exists(Server.MapPath("~/File")) == false)判断资料夹是否存在,若不存在则建立
{
Directory.CreateDirectory(Server.MapPath("~/File"));
}
else
if (IsAllowableFileSize())
{
string UploadFilePath = ConfigurationManager.AppSettings["UploadFile"].ToString();
string UploadFilePath = Server.MapPath("File\");
string fullName = FileUp.PostedFile.FileName;
string newName = DateTime.Now.Ticks.ToString() + fullName.Substring(fullName.LastIndexOf("."));
FileUp.SaveAs(UploadFilePath + newName);
lblFileUrl.Text = fullName.Substring(fullName.LastIndexOf("\")) + " 上传成功";
lblSaveFileName.Text = newName;
}
else
MessegeBox.Show(this, "档案太大了,上传失败");
}
else
MessegeBox.Show(this, "档案型别不正确,上传失败");
}
else
{
MessegeBox.Show(this, "上传档案为空,上传失败");
}
}
到这里,档案已经上传到一个File资料夹中了,当然,如果要把路径储存到资料库,你需要另外写一个储存路径到资料库的方法,在此就不在赘述了
如何将.dat档案用c#显示出来,求完整程式码
你指的 dat 档案应该存放的是自定义的资料,若是没加密的话直接读取档案资料,然后转换成对应的资料(一般都是字串)就行,若是存放的是各种资料,如 int、double 的话这样的档案应该有存放的规律的,分段、有规律的读取资料,然后对应格式的转换就行了,前提是你得知道存放的方式。
我弄过科洛斯的服务端资料档案修改工具,方法就是我说的这种,分析 dat 档案资料构成,然后相应的读取资料,转换,显示,就OK了,修改的话一样的道理。
求C#连线SQL完整程式码
请参阅以下指令码程式码:

String connsql = "server=.;database=资料库名称;integrated security=SSPI"; 资料库连线字串,database设定为自己的资料库名,以Windows身份验证 try { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connsql; conn.Open(); 开启资料库连线 String sql = "select * from [表名]"; 查询语句 SqlDataAdapter myda = new SqlDataAdapter(sql, conn); 例项化介面卡 DataTable dt = new DataTable(); 例项化资料表 myda.Fill(dt); 储存资料 dataGridView1.DataSource = dt; 设定到DataGridView中 conn.Close(); 关闭资料库连线 } } catch (Exception ex) { MessageBox.Show("错误资讯:" + ex.Message, "出现错误"); }
c# 怎么读取指定资料夹下的第二个档案。求完整程式码。
直接使用C#遍历指定资料夹中的所有档案就可以实现;
参考如下:
DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);
遍历资料夹
foreach(DirectoryInfo NextFolder in TheFolder.GetDirectories())
this.listBox1.Items.Add(NextFolder.Name);
遍历档案
foreach(FileInfo NextFile in TheFolder.GetFiles())
this.listBox2.Items.Add(NextFile.Name);
你要读取第二个档案 那么直接读取listBox2.Items[1]里面的档名 然后用指定档案路路径去取档案 就行了
C++编一个程式,求完整程式码以及注释
public class Test { /** * 公鸡每只值五文钱, * 母鸡每只值三文钱, * 小鸡每三只值一文钱。 * 现在用一百文钱买一百只鸡。 * 问:这一百只鸡中,公鸡、母鸡、小鸡各有多少只? */ public static void main(String[] args) { 公鸡最大数:100/5=20 for (int a = 1; a <= 20; a++) { 母鸡最大数:100/3=33 for (int b = 1; b <= 33; b++) { 计算小鸡只数 int c = 100 - a - b; 判断价格等于100 且 只数和等于100 且 小鸡数量能被3整除 if (5 * a + 3 * b + c / 3 * 1 == 100 && a + b + c == 100 && c % 3 == 0) { System.out.println("公鸡=" + a + "母鸡=" + b + "小鸡=" + c); } } } }}vb矩阵问题求完整程式码
Option Explicit
Dim a(3, 3) As Integer, b(3, 3) As Integer, c(3, 3) As Integer
Dim i As Integer, j As Integer
Private Sub Command1_Click()
Me.Cls
Randomize
For i = 1 To 3
For j = 1 To 3
a(i, j) = Int(Rnd * 100) + 1
b(i, j) = Int(Rnd * 100) + 1
c(i, j) = a(i, j) + b(i, j)
Next j
Next i
Print "随机阵列:A"
For i = 1 To 3
For j = 1 To 3
Print a(i, j) & vbTab;
Next j
Print
Next i
Print "随机阵列:B"
For i = 1 To 3
For j = 1 To 3
Print b(i, j) & vbTab;
Next j
Print
Next i
Print "两个阵列的和"
For i = 1 To 3
For j = 1 To 3
Print c(i, j) & vbTab;
Next j
Print
Next i
End Sub