许多控件enable设置为false后就变成灰色,怎么能让他只读且不为灰色?

flankerfc 2007-06-04 11:02:13
有些控件没有Readonly属性
(比如ComboText,CheckBox,DatetimePicker,TreeView)
想让它只读只好把enable设置为false
但是这样子就显示成灰色了 很难看
请问怎么样来正常显示?
或者有什么别的方法来设置只读?
...全文
867 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
flankerfc 2007-06-04
  • 打赏
  • 举报
回复
LS可否详细说明下 谢谢了
lldwolf 2007-06-04
  • 打赏
  • 举报
回复
就把控件重载一下好了, 重写相关的事件处理程序
D_Mosquito 2007-06-04
  • 打赏
  • 举报
回复
有意思,关注
BearRui 2007-06-04
  • 打赏
  • 举报
回复
在控件的keydown事件中截获所有按键信息,一样实现无法输入的效果。
flankerfc 2007-06-04
  • 打赏
  • 举报
回复
忘说了 是WinForm
fffxcg 2007-06-04
  • 打赏
  • 举报
回复
可能的化,用CSS样式来控制。
jiatong1981 2007-06-04
  • 打赏
  • 举报
回复
如果允许的话 可以考虑使用第三方控件



DevExpress系列控件都提供有readonly属性
flankerfc 2007-06-04
  • 打赏
  • 举报
回复
LS大哥 关键是好多控件都没有ReadOnly属性啊
(比如ComboText,CheckBox,DatetimePicker,TreeView)
ismezy2002 2007-06-04
  • 打赏
  • 举报
回复
ReadOnly = true;
alldj 2007-06-04
  • 打赏
  • 举报
回复
画个控件上去,把原控件隐藏掉。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace TestDLL
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
ArrayList arry=new ArrayList();
public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form1_Paint);
}

void Form1_Paint(object sender, PaintEventArgs e)
{
for (int i = 0; i < arry.Count; i++)
{
e.Graphics.DrawImage(((Bitmap)((object[])arry[i])[0]), ((Point)((object[])arry[i])[1]));

}
}
private void DrawImage(Control c)
{
Size s = c.Size;
Graphics mygraphics=c.CreateGraphics();
IntPtr dc1;
IntPtr dc2;
Bitmap memoryImage = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
dc1 = mygraphics.GetHdc();
dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, c.ClientRectangle.Width, c.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
Point p = new Point(c.Location.X, c.Location.Y);
Panel pa = new Panel();
object[] obj ={ memoryImage, p};
arry.Add(obj);
c.Visible = false;
this.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
DrawImage(this.treeView1);
DrawImage(this.comboBox1);
}
}
}

111,111

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧