In my current job we are not allowed to use databinding. I’m currently using a code generator (ORM) to generate the data layer objects. In the past I usually generated a data source (from the object) and do a drag and drop to automatically add the controls (with the correct databinding to the WinForm).
Is there is a way to do something similar (programmatically) using Visual Studio?
I tried to use the a copy and paste approach (by analyzing the data of the control, in the clipboard, generated by VS), but unfortunately the format used by VS to serialize the control to the clipboard is binary (I was hoping that the format was XML because I can easy modify that). Other approaches I tried was generating the designer code using a code generator. Unfortunately this only works if I want to create a new form but it is, from a practical point, unworkable if you want to add new controls to an existing form.
Controls are just objects. Any properties you can set in the designer can be set in code as well. And event handlers are just delegates. You can build the entire GUI without using the designer at all -- just write the code. I've done this several times with dynamically-generated GUI elements.
Spend some time reading through the code that the Visual Studio designer generates, and you'll quickly see how to do the same things by hand.
Related
I'm using a VB6 application as a reference and have come across imgMain. I'm assuming its an image control, however, I cannot find the object on any of the forms. It's used to load the image. I'm just not sure what's going on with this. I'm assuming its an IMAGE CONTROL, but I cannot find this on any of the forms? it's mentioned a lot of times in teh application as it lets you view incoming faxes and stuff.
Without having a look on source code i assume It might be custom user control that was created for some reasons probably to extend basic picturebox control.
One thing i can advise you is to further inspect code and dig to code of this custom control. If code for this control is not available then see what methods and properties instances of that particular control uses and compare them with regular picturebox.
I started with Coded UI Tests. So far so good, but I have one concern about the file UIMap.uitest. Since I have to create many test scenarios, means many cs files. The more files I have, the bigger the UIMap.uitest is, because it keeps regenerating the code all the time. My question is that it's possible to have/create each UIMap.uitest for each cs file, respectively?
I am using VS2010.
Thanks
Yes. Look for information on "multiple ui maps". The general approach is to right-click in solution explorer, add a new item that is a "Coded UI test map" (Add => New item => Visual C# items (or possibly VB) => Test => Coded UI test map). After naming the map and clicking OK the normal Coded UI dialogues should appear allowing recording and generating of new items. Some people recommend creating a folder in solution explorer to contain all the UI maps. After recording and generating code, calls of the generated methods will need to be added manually to the test methods. Additionally, these new UI maps will need to be instantiated. This Microsoft blog has some more details http://blogs.msdn.com/b/anutthara/archive/2010/02/10/walkthrough-using-multiple-coded-ui-maps-in-test-automation.aspx
When using multiple UI maps DO NOT right click in the source files and select the "Generate code for Coded UI test". If you do then the code will be added to the default "UImap.uitest" file, creating one if needed and with no warning that it is doing so. (See also http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3378897-choosing-the-uimap-when-recording-tests )
I have not found any way of moving items from one UI map file to another except by editing their XML sources and that is complicated.
I am building a code generation tool using vs 2010 visualisation & modelling sdk. One of the things that I need to generate is a simple data capture ui (windows forms, preferably using devexpress layout control), with capture fields & labels for each property in a class.
I can use t4 text templates to do this, but I am conscious that I will be re-inventing the wheel if I do this - a simpler approach would be to add controls to a form constructed at runtime and allow the appropriate codedomseriaizer to generate the form.designer.cs code for me - is this possible?
To summarise, I would like to build a form at runtime, and retrieve a string of the designer.cs file..
Graham
Could you not simply leave the runtime generation code in use, and design only the other parts of the form using the designer? This way the autogenerated controls will be automatically updated if new properties are added to the class.
I'm looking for some high-level help with determining the best type of Visual Studio 2010 project to use for an Excel custom application.
I will be developing a program that requires the user to enter a dataset in a particular way. Not using a form per se, but rather in columns and the program will need to do some custom validation on the items in order to prep the data. From there, the user will be able to conduct various operations on the data via a custom Ribbon and associated options. The program will also transmit the data via web service.
I've fooled around with the Add-In project and that gives me a lot of what I need but I'm wondering if a Template or Workbook project is better for this in terms of data entry and being able to "guide" the user a little more.
How do you go about choosing between which project type to use? Do all the project types support a custom Ribbon?
Sorry if this is too far off topic. I'm referring to VBA, not Visual Studio, but it might still be relevant.
With an AddIn, compared to a Workbook, you can separate your code from the user's data. So, if the code is complex, and you'll need to update it separately from user's workbooks with data, this is not a bad idea.
With an AddIn, you can add buttons that do things like check to make sure the user data workbook is ok, or process it in someway. However, the AddIn custom buttons will load ever time a user opens any Excel worksheet. This doesn't sound good, but in practice, isn't so bad. You can code your AddIn so it does nothing as long as no one uses a button, so it almost doesn't hurt load times, etc...
A Workbook might be useful if you need to really guide the user - that is, you cannot rely on the user to hit a button to verify something, and instead you need to verify on every change, for example. However, the workbook solution incorporates the user data and your code in the same workbook, so if you need to update the code for existing users' data, that's harder.
I use a combination of AddIn (.xlam) with buttons, and a template (with minimal self-describing data only).
I'm not sure about the template-only option, so won't comment on that.
Is it possible to configure a Ribbon (e.g. adding a tab etc.) in Office 2010 programatically via VBA? I.e. by writing VBScript code in a macro.
Br. Morten
You can manipulate a Ribbon tab and its controls using VBA, but you cannot create one. Not with the Object Model anyway. The best you could do - somehow - is to get some kind of OPC dll (like an ActiveX component) that handles opening/relationships/closing of OPC documents (like .docx documents) and old school MSXML for creating a ribbon definition and adding it to the package.
Have a look at this blog post for Excel
http://www.xtremevbtalk.com/showthread.php?t=265636
and this one for Word
http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm
If your UI is static, i.e. you don't need to programatically change the behavior of, or add/remove UI elements on the fly, you can define a customUI within a macro-enabled template. You can use your VBA functions as call-backs for the UI elements defined in the XML.
Have a look at this guide. In a nutshell, you define a customUI\customUI14.xml file within the .dotm archive. This XML describes your custom ribbon elements using this schema.
This definitely works for Word templates (.dotm files). I think a similar approach works for any OOXML format.