Dotnetinfo’s Weblog

Just another WordPress.com weblog

Archive for the ‘Reflection’ Category

c# Reflection or Verbs or Design Time help document

Posted by dotnetinfo on October 29, 2008

The article explains how to use reflection to view resource data or how to use verbs to display design time help documents

As always thousand ways to implement something so use the document as a path not as a pattern

Step 1 : Create a HTML/XML/ …. file and Set Build Action to Embedded Resources

 

Step 2 :  Create a windows form with the example code to read the data from assembly

 

private void LoadData(string ResourcePath)

        {                                   

            try

            {

                

                if (!String.IsNullOrEmpty(ResourcePath))

                {

                   

                    Assembly assembly = Assembly.GetExecutingAssembly();

                    StreamReader sr = new StreamReader(assembly.GetManifestResourceStream(ResourcePath));

                    if (sr == null)

                        MessageBox.Show(“Resource is null for “ + ResourcePath);

                    string partialContent = sr.ReadToEnd();                   

                    DataDetails.Text = partialContent;                   

                    GenericHelp.ActiveForm.Activate();

                }

                else

                {

                    MessageBox.Show(“ResourcePath not assigned for display”);

                }

               

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message.ToString());

            }

           

           

        }

 

Step 3: In VersionControlDesigner in Designers add a new control desginer

 

public class SomeControlDesigner : ControlDesigner

      {

        public override System.ComponentModel.Design.DesignerVerbCollection Verbs

        {

            get

            {

                DesignerVerbCollection v = new DesignerVerbCollection();

                v.Add(new DesignerVerb(“Help link”, new EventHandler(HelpVerbHandler)));

                return v;

            }

        }

 

        private void HelpVerbHandler(object sender, System.EventArgs e)

        {

 

            OpenForm();

 

        }

 

        // write process to open web form

        private void OpenForm()

        {

            // Resource Path need to be passed with intialization

            GenericHelp gh = new GenericHelp(“Full file name – Case Sensitive”);                                        

            gh.ShowDialog();

        }

 

 

Step 4 :  In SomeControl.cs add a attribute –

[Designer(typeof(NameSpace.SomeControlDesigner))]

 

Step 5 : In Designer mode , view property window you will see a link and Click on the link will open window form

Posted in C#, Design Time, Reflection | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.