Step by Step Master sharpdevelop4, create your own pad, and view

Source: Internet
Author: User

In SD, pad and view are difficult to grasp, because the calling relationship is complicated. I did not directly look at the code, but borrowed
Http://www.cnblogs.com/michael-zhang/articles/629724.html
Below is a part of the demo. How to Use SD to create a pad and view?

This demo simplifies some of the Code in the system and looks intuitive to analyze.

We can see that a main window is workbench with a menu, a toolbar, two pads, and a contentview,
Workbench implements an iworkbech Interface

We can see from the figure that one of them is an open file with the file name being written to the code.
From the command we sent to open a file, the file is displayed in front of us. The process is as follows:

BTN sends a command to open a file and calls-> fileservice,
Fileservice must create a viewcontent for this file and add it to the viewcollection set of workbench

How can I find the viewcontent corresponding to this file,
Fileservice calls displaybindingservice and finds an idisplaybinding that can open this file and create a view.

 

Public interface idisplaybinding
...{
/** // <Remarks>
/// This function determines, if this display binding is able to create
/// An iviewcontent for the file given by filename.
/// </Remarks>
/// <Returns>
/// True, if this display binding is able to create
/// An iviewcontent for the file given by filename.
/// False otherwise
/// </Returns>
Bool cancreatecontentforfile (string filename );

/** // <Remarks>
/// Creates a new iviewcontent object for the file filename
/// </Remarks>
/// <Returns>
/// A newly created iviewcontent object.
/// </Returns>
Iviewcontent createcontentforfile (string filename );
}

Displaybindingservice: Find the idisplaybinding that can open this file from the displaybindingdescriptor set.
After the idisplaybinding is returned, fileservice calls the idisplaybinding. createcontentforfile method to create a view and returns an iviewcontent

Now that we understand this, we will make our own binding, which is easier than our own service.
Step 1: Create a class that implements idisplaybinding and point out the file types that can be opened.

 

Public class housemandisplaybinding: idisplaybinding
...{
Idisplaybinding members # region idisplaybinding members

Public bool cancreatecontentforfile (string filename)
...{
Filename = filename. tolower ();
Return filename. endswith (". Con ");
}

Public iviewcontent createcontentforfile (string filename)
...{
Condisplaybindingwrapper imgdisplay = new condisplaybindingwrapper ();
Imgdisplay. Load (filename );
Return imgdisplay;
}

# Endregion

}

Second, perform the iviewcontent corresponding to this file type.

 

Public abstract class abstractviewcontent: iviewcontent ...{//......}

Public class condisplaybindingwrapper: abstractviewcontent
...{

Panel _ panel;

Public override control Control
...{
Get
...{
Return _ panel;
}
}


Public override void load (string filename)
...{
Control con = new housecon (); // a very simple and small Control Based on usercontrol
Con. Location = new point (1, 1 );

_ Panel = new Panel ();
_ Panel. autoscroll = true;
_ Panel. Dock = dockstyle. Fill;
_ Panel. tabindex = 1;
_ Panel. Controls. Add (CON );

Titlename = system. Io. Path. getfilename ("control ");
}

Public override void dispose ()
...{
_ Panel. Controls. Clear ();
_ Panel = NULL;
}
} Step 3: add the binding to The addin file of the program.

 

 

<Displaybinding id = "control"
Insertbefore = "text"
Supportedformats = "control"
Class = "sharpgui. viewcontent. housemandisplaybinding"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.