1: using System;
2: using System.Drawing;
3: using System.Security.Permissions;
4: using System.Windows.Automation;
5: using System.Windows.Automation.Provider;
6: using System.Windows.Forms;
7:
8: namespace WindowsFormsApplication1
9: { 10: public partial class UIAPanel : Panel, IRawElementProviderSimple
11: { 12: public UIAPanel()
13: { 14: this.BackColor = Color.Yellow;
15: this.Height = 0;
16: this.Width = 0;
17: this.AutoSize = true;
18: }
19:
20: [PermissionSetAttribute(SecurityAction.Demand, Unrestricted = true)]
21: protected override void WndProc(ref Message m)
22: { 23: // 0x3D == WM_GETOBJECT
24: Int32 param = 0;
25: if (Int32.TryParse(m.LParam.ToString(), out param))
26: { 27: if ((m.Msg == 0x3D) && (param == AutomationInteropProvider.RootObjectId))
28: { 29: m.Result = AutomationInteropProvider.ReturnRawElementProvider(
30: Handle, m.WParam, m.LParam, (IRawElementProviderSimple)this);
31: return;
32: }
33: }
34: base.WndProc(ref m);
35: }
36:
37: #region IRawElementProviderSimple Members
38:
39: public object GetPatternProvider(int patternId)
40: { 41: if (patternId == ValuePatternIdentifiers.Pattern.Id)
42: { 43: return this;
44: }
45: else
46: { 47: return null;
48: }
49: }
50:
51: public object GetPropertyValue(int propertyId)
52: { 53: if (propertyId == AutomationElementIdentifiers.ClassNameProperty.Id)
54: { 55: return "CalendarPanel";
56: }
57: else if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
58: { 59: return ControlType.MenuBar.Id;
60: }
61:
62: if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
63: { 64: return "Help for CalendarPanel";
65: }
66:
67: if (propertyId == AutomationElementIdentifiers.AutomationIdProperty.Id)
68: { 69: return this.Name;
70: }
71:
72: if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
73: { 74: return true;
75: }
76:
77: else
78: { 79: return null;
80: }
81: }
82:
83: public IRawElementProviderSimple HostRawElementProvider
84: { 85: get
86: { 87: return AutomationInteropProvider.HostProviderFromHandle(Handle);
88: }
89: }
90:
91: public ProviderOptions ProviderOptions
92: { 93: get
94: { 95: return ProviderOptions.ServerSideProvider;
96: }
97: }
98:
99: #endregion
100:
101: }
102: }