C# 问题 ?? winfrom中 窗体form1上我添加了一个label1,我想达到 鼠标单击label1,在label1旁边显示出可选的下级目录(下级目录也用lable来显示),在点击某一个下级目录时执行Click事件 怎么做??望高手指教!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的下级目录有很多条内容吗?一条内容的话就点击第一个label的时候给第二个label负值。再点击再执行click事件啊。 很繁琐,没有特殊要求,推荐使用TreeView控件 我有8个lable 关键时怎么显示出下一个呢 你在第一个label的click事件给第二个label负值不能显示吗? 我有8个下级目录 用 lable来显示。关键是怎么让下级显示出来呢?? this.label2.Text = "3";不是吗?你想要做什么? 如果你的下级目录的内容不是从数据库中抽出的那就直接负值啊。下级目录的label付对应的值啊。 private void label1_Click(object sender, System.EventArgs e) { this.label2.Text = "2"; this.label3.Text = "3"; this.label4.Text = "4"; this.label5.Text = "5"; this.label6.Text = "6"; this.label7.Text = "7"; this.label8.Text = "8"; this.label9.Text = "9"; }不是这样吗? private void label1_Click(object sender, EventArgs e) { for (int i = 0; i != 8; i++) { Label Lab = new Label(); Lab.Name = i.ToString(); Lab.Click += new EventHandler(Lab_Click); Lab.Text = i.ToString(); Lab.Size = label1.Size; int Height = label1.Location.Y + (label1.Height * i); Lab.Location = new Point(label1.Location.X + label1.Width, Height); label1.Parent.Controls.Add(Lab); } } void Lab_Click(object sender, EventArgs e) { Label _Label = (Label)sender; MessageBox.Show(_Label.Name); }感觉还是 TreeView好用 硬要喊用lable的嘛 谢谢了 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication2{ public partial class Form1 : Form { Label[] lblMenus; bool blnClick; public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { Rectangle rect; Label lblMenu; if (lblMenus == null) { lblMenus = new Label[8]; for (int i = 0; i < 8; i++) { lblMenu = new Label(); lblMenu.Text = "AAAA" + i.ToString(); if (i == 0) { rect = label1.Bounds; } else { rect = ((Label)lblMenus.GetValue(i - 1)).Bounds; } lblMenu.Left = rect.Left; lblMenu.Top = rect.Bottom; lblMenu.Size = new Size(label1.Width, label1.Height); this.Controls.Add(lblMenu); lblMenu.Click += new EventHandler(lblMenu_Click); lblMenu.Show(); lblMenus.SetValue(lblMenu, i); } blnClick = true; } if (blnClick == true) { for (int i = 0; i < 8; i++) { ((Label)lblMenus.GetValue(i)).Visible = true; } blnClick = false; return; } else { for (int i = 0; i < 8; i++) { ((Label)lblMenus.GetValue(i)).Visible = false; } blnClick = true; } } void lblMenu_Click(object sender, EventArgs e) { //throw new Exception("The method or operation is not implemented."); for (int i = 0; i < 8; i++) { ((Label)lblMenus.GetValue(i)).Visible = false; } blnClick = true; Label lbl = sender as Label; MessageBox.Show(lbl.Text); } }} 有没有查找一个字符串在另外一个字符串中第N次出现的位置的函数 (C#)winform中实现选择一个文件夹,将其压缩复制到另外一个路径 DataGrid控件對數據進行刪除 C#动态生成文字图片时,为什么不支持非系统字体? 求一思路 多线程和XML的问题 问几个简单问题? 关于listbox, combobox, button 有图片,做一个N皇后问题的网页 给位大神给我的思路吧 这俩个问题实在解决不了了,大虾帮帮忙!!!!!! 请问一些简单的初级问题 求助 有关 new listitem 日期类型 2008-8-8 如何与int 20080808 做比较!
一条内容的话就点击第一个label的时候给第二个label负值。
再点击再执行click事件啊。
不是吗?你想要做什么?
private void label1_Click(object sender, System.EventArgs e)
{
this.label2.Text = "2";
this.label3.Text = "3";
this.label4.Text = "4";
this.label5.Text = "5";
this.label6.Text = "6";
this.label7.Text = "7";
this.label8.Text = "8";
this.label9.Text = "9";
}不是这样吗?
{
for (int i = 0; i != 8; i++)
{
Label Lab = new Label();
Lab.Name = i.ToString();
Lab.Click += new EventHandler(Lab_Click);
Lab.Text = i.ToString();
Lab.Size = label1.Size;
int Height = label1.Location.Y + (label1.Height * i);
Lab.Location = new Point(label1.Location.X + label1.Width, Height); label1.Parent.Controls.Add(Lab);
}
} void Lab_Click(object sender, EventArgs e)
{
Label _Label = (Label)sender;
MessageBox.Show(_Label.Name);
}感觉还是 TreeView好用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
Label[] lblMenus;
bool blnClick; public Form1()
{
InitializeComponent();
} private void label1_Click(object sender, EventArgs e)
{
Rectangle rect;
Label lblMenu; if (lblMenus == null)
{
lblMenus = new Label[8];
for (int i = 0; i < 8; i++)
{
lblMenu = new Label();
lblMenu.Text = "AAAA" + i.ToString();
if (i == 0)
{
rect = label1.Bounds;
}
else
{
rect = ((Label)lblMenus.GetValue(i - 1)).Bounds;
}
lblMenu.Left = rect.Left;
lblMenu.Top = rect.Bottom;
lblMenu.Size = new Size(label1.Width, label1.Height);
this.Controls.Add(lblMenu);
lblMenu.Click += new EventHandler(lblMenu_Click);
lblMenu.Show();
lblMenus.SetValue(lblMenu, i);
}
blnClick = true;
} if (blnClick == true)
{
for (int i = 0; i < 8; i++)
{
((Label)lblMenus.GetValue(i)).Visible = true;
}
blnClick = false;
return;
}
else
{
for (int i = 0; i < 8; i++)
{
((Label)lblMenus.GetValue(i)).Visible = false;
}
blnClick = true;
}
} void lblMenu_Click(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
for (int i = 0; i < 8; i++)
{
((Label)lblMenus.GetValue(i)).Visible = false;
}
blnClick = true;
Label lbl = sender as Label;
MessageBox.Show(lbl.Text);
}
}
}