在我的WindowsForm窗体里放了一个Propertygrid,请问在runtime时如何让Propertygrid显示其他Control的扩展属性(ProvideProperty)?

photoboy 2007-11-29 09:45:07
以下是我的范例程序,如果我在Visual Studio 2005开发环境设计WindowsForm的画面中拉一个MyPanel迈来,并在其上放一个Label,当我选取该Label对象时,属性视窗(Property window)会显示该对象的属性,且会另附加上ControlIndex属性,但是我实际执行范例程序时,在执行时期的Propertygrid对象里,会显示label2对象的属性,可是没有附加上ControlIndex属性。请问我该如何修改,才能让Runtime的Propertygrid显示对象的附加属性(ProvideProperty)?

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

namespace TestProvideProperty
{
public partial class Form1 : Form
{
private PropertyGrid propertyGrid1 = new PropertyGrid();

public Form1()
{
InitializeComponent();

propertyGrid1.Dock = DockStyle.Fill;
this.Controls.Add(propertyGrid1);
}

private void Form1_Load(object sender, EventArgs e)
{
MyPanel panel1 = new MyPanel();

Label label1 = new Label();
label1.Text = "label1";
panel1.Controls.Add(label1);

Label label2 = new Label();
label2.Text = "label2";
panel1.Controls.Add(label2);

propertyGrid1.SelectedObject = label2;
}
}

[ProvideProperty("ControlIndex", typeof(Control))]
public class MyPanel : Panel, IExtenderProvider
{
[DisplayName("ControlIndex")]
public int GetControlIndex(Control sender)
{
return this.Controls.GetChildIndex(sender);
}

[DisplayName("ControlIndex")]
public void SetControlIndex(Control sender, int value)
{
this.Controls.SetChildIndex(sender, value);
}

bool IExtenderProvider.CanExtend(object extendee)
{
Control c = extendee as Control;
if (c != null)
{
return (c.Parent == this);
}
return false;
}
}
}

...全文
161 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2007-11-30
  • 打赏
  • 举报
回复
好像是只有在设计的时候可以.
uses winskindlg; Type TMySkinManage=class(TSkinManage); procedure TForm1.btn1Click(Sender: TObject); //破解后的2.6版不能够动态改变窗体的caption,下面是补充解决办法 var P: Pchar; begin P := Pointer(TMySkinManage(SkinManager).FindSkinForm(Handle)); if P = nil then exit; P := P+104; //D5的话请将104改为88,未经测试 Pstring(P)^ := 'Edit1.Text'; Caption := 'Edit1.Text'; ////////////////////////////////////////////// end; Delphi VclSkin 2.60 VCLSkin is an VCL library that extend Delphi application with skinnable user interface . Unlike other skin component that you must modify source code to build skinnable application, VCLskin can skin existing application using VCL components without source code modification. VclSkin automatically skin kinds of windows in application, include Delphi forms,MDIform and common Windows dialogs (MsgBox,Open/Save,Font,Print), even the Exception MsgBox. Vclskin not only support Delphi standard controls, but also support many third-party component, such as TMS Grid pack, EnLib Grid, Developer Express QuantumGrid. It is an excellent choice for those wanting to skin existing applications. The cool thing is that it uses existing VCL components. Demo version adds a string 'VclSkin demo' on form caption, but allows to test all available functions. News in 2.60 *Support Arabic language, BiDiMode is righttoleft. *Fixed some bugs when application closed. News in 2.55 *Fixed bug that Tspeedbutton destory at runtime. *Improve performance when change menutitem at runtime. *Fixed OpenDialog bug. News in 2.50 *Support LMD tools. *Fixed bug of checkbox that is disabled . *Add TSkindata.Skin3rd property to add 3rd control easily. News in 2.45 *Some bugs fixed. *Improve compatibility with Billenium effects. News in 2.4 *Support to skin an application but keep the menu bar and title bar the default Windows standard. *DBCheckbox bug fixed. *Fixed bug in cascade,tile command in MIDform. *Bug with minimized state when form created. *Suport ReportBuilder News in 2.3 *Support TUpDown and TSpinEdit. *Support TrackBar. *Restore form size when remove skin. *Fix more bugs. News in 2.25 *Fix bug with QuickReport and FastReport. *Fix bug in Tstatusbar. *Fix bug in Application. News in 2.20 *Support Header control in TlistView. *Fix Menuitem ShortCut bug. *Fix bug that change windows Z-Order when skin change at runtime. *Support Tframe created at runtime. News in 2.10 *Fix Scrollbar drag thumb problem. News in 2.05 *Support multi-skindata in application,Mainform and messagebox can use different skindate. *Nested form support. *Fixed Title flicker problem when form resize. *Support Mainmenu change at runtime. News in 2.0 *skin kinds of windows in your project, Delphi forms,MDIform and common Windows dialogs (MsgBox,Open/Save,Font,Print), even the Exception MsgBox. *Enable/Disable skin at runtime. *fixed many bugs in MDIform. *system menu enchanced. website : http://www.link-rank.com email : info@link-rank.com

111,095

社区成员

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

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

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