Hi Guys,
as you may have seen in the Phidgets plugin, I've realized to "inject" stuff on the Main screen of CF.
I thought this could be a nice tool to have, so I made an Assembly out of it and I'm sharing this with you.
How to use it:
1. Download
CFInjector and unzip the files.
2. Add a reference to the assembly in your VS2003 project file.
3. Add these lines of code:
Somewhere in your class add these members:
Code:
private XmlDocument skinXml = new XmlDocument();
private InjectorTools injector = new InjectorTools();
Somewhere in CF_localskinsetup add this code:
Code:
//---------------------------------------------------------------------
// load the main skin
//---------------------------------------------------------------------
try
{
skinXml.Load(MainPathSkins + currentSkin +@"\skin.xml");
injector.ClearCachedControls();
injector.SkinXml = skinXml;
injector.MainForm = this.MainForm as Form;
injector.SkinRatio = new PointF((float)SkinReader.widthratio, (float)SkinReader.heightratio);
}
catch ( Exception ex )
{
Debug.WriteLine("Main skin not loaded. " + ex.ToString());
}
Whereas MainPathSkins is a constant pointing to the "Skins" folder.
Red marked lines apply to version 2.2.0.0, which allows resizing the injected controls as skins get streched because of an higher or lower resolution.
Somewhere in your plugin code add:
Code:
injector.InjectText("LABEL1", "Some text");
to inject text only
or
Code:
Image image = Image.FromFile( "path and filename of the image to inject" );
if(image != null)
injector.InjectImage("LABEL1", image);
to inject an image from a file.
To have the injections updated, you may have to set up a timer which will refresh the injected controls frequently. So your timer event will need this line to refresh the injections:
Code:
injector.DrawInjectedControls();
That's all that has to be done in your code.
Beside, you have to modify the Skin.xml from the according Skin folder where you want to inject something in this way:
1. Add a section to
Code:
<SKIN>
<SCREENS>
<MAIN>
and name it
<INJECT></INJECT>.
2. Add one or more standard CF Label controls to it, such as in:
Code:
<INJECT>
<LABEL1>
<WORDWRAP>False</WORDWRAP>
<FONTCOLOR>#696969</FONTCOLOR>
<FONTNAME>You Rook Marbelous</FONTNAME>
<FONTSIZE>14</FONTSIZE>
<FONTSTYLE>Bold</FONTSTYLE>
<Y>48</Y>
<X>518</X>
<WIDTH>70</WIDTH>
<HEIGHT>30</HEIGHT>
<ALIGN>Left</ALIGN>
</LABEL>
</INJECT>
In the sample above we now have a Label with the ID LABEL1.
3. Save the skin file and run your plugin. The rest will CFInjector do for you.
If you're using VD2, you can speed things up by adding label controls to the main skin panel and adding a prefix called INJECT:: to the Id property, such as:
INJECT::LABEL1
When exporting the skin, VD2 will create the section for you and put all labels into it (see also the Id property of the MAINPAGEBUTTONS if this is unclear).