Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


How do I use one form showing two different look

Postades av 2006-02-22 09:23:25 - Tony Johansson, i forum c# (c-sharp), Tråden har 6 Kommentarer och lästs av 514 personer

Hello!!

I'm using C#

Assume I have an application containing a form named form.cs.
When you create the look for the form you use the form designer
to construct the look that you want.

All changes that you do in form designer are put into method InitializeComponent.

Assume the form have many more controls than these three controls mentioned just below.
The controls that are interesting for my question are:
Two buttons called put_in_box and get_from_box.
One label showing the correct time.
One datagrid.

The property for these controls is located in the InitializeComponent as I mentioned earlier.

Assume another customer requirement on the form is quite similar to form form.cs.
The only difference is that some controls should not be displayed and some other controls be added instead.

The followings controls should not be displyed for the new customer.
The two buttons named put_in_box and get_from_box.
A label showing current time.
A datagrid.

The new customer want to have a combobox in the same location as the datagrid.

We can assume that if you compare the appearance of the form between the two customer much is the same.

Now to my problem.
1. I want to have only one form in this case form.cs. So no duplication of code.
2. In an easy way being able to have two appearance(look) of the same form which is named form.cs.
3. Being able to change the appearance(look) for any of these two customer in an easy way..
4.The form designor is always looking for InitializeComponent when you want to change the appearance(the look) for the form.
5. If I had used MFC I would have used the resource files which store the look for a form in a named resource file. One customers look had been stored in one resource file and the other customer look would have been stored in another resource file but the code would only be in one place so no duplicate code


I can't find any good solution to my problem.

- One solution which is bad is to have two forms having one form for each customer which also duplicate the code. For example having form.cs and form_xyz.cs
- Another solution which is very bad is to have two InitializeComponent
InitializeComponent_abc and InitializeComponent_xyz. One for each customer.
When you want to edit the appearance(the look) for a customer xyz you have to rename InitializeComponent_xyz to InitializeComponent because the form designed is always looking for InitializeComponent. As a summary a lot of renaming here and there.

I wonder if you could help me with a good solution if there exist one.

Many thnaks!

//Tony


Svara

Sv: How do I use one form showing two different look

Postades av 2006-02-22 11:33:55 - Emma Magnusson

Well, You could look at userControls, do one where you put everything that the controls have in common, then inherit it to two seperate controls, where you put all the specifics.

Then you just have to choose which userControl to display in your form. And when to load/unload the other.

/Emma


Svara

Sv: How do I use one form showing two different look

Postades av 2006-02-22 12:31:58 - Joakim Rosendahl

Hi.

Could this be done by adding a method to your form called setApperance(..)? The method setApperance(..) will set the controls you don't want to show as invisible and vice verse with the controls you want to show. It's not the fanciest solution though =).

good luck anyway!


Svara

Sv:How do I use one form showing two different look

Postades av 2006-02-22 15:37:55 - Tony Johansson

Hello!!


Thanks for you answer.

The most normal is to add the userControl to the form manually.

Because you mentioned about load and unload is it possible to load the userControl dynamicall which mean the program load some specific userControl based on some value from the database.

Do you know which class and method takes care of this loading and unloading

//Tony


Svara

Sv: How do I use one form showing two different look

Postades av 2006-02-22 22:24:36 - Andreas Hillqvist

I would have put th common code in one form and create two new forms that inherits the common form.
Adding the diffrent code to this two new forms.

This could be more useful for an larger mor complelex for where only litele of the form differ.
Dont know how this tip works for you. That is upp to you.


Svara

Sv: How do I use one form showing two different look

Postades av 2006-02-23 10:15:00 - Emma Magnusson

Well, From what I can understand you display the form at all times, it's just the contents that's suppose to differ. If that is the case:

- How do you get your information from the database? By an event of some sort?
- In the method where you get the database-information put in a select case/if-else or how ever you like to check the value, and choose to load the usercontrol.
- The easiest way is to load them both at startup and just alter their visability depending on the database status.

But you really ought to have three userControls as I mentioned in my first post, then you won't have the problem of having the same code in two places. Put all that's common in one, inherit it to the two usercontrols that you wish to display and build them.

Hope that's helpfull.

/Emma


Svara

Nyligen

  • 08:28 Butiksskyltar: Hur upplever utbude
  • 22:31 Slappna av
  • 19:55 kick-off med fokus på hälsa?
  • 19:53 kick-off med fokus på hälsa?
  • 16:24 Föreslå en skönhetsklinik online
  • 16:23 Föreslå en skönhetsklinik online
  • 18:42 Hvor finder man håndlavede lamper
  • 18:41 Hvor finder man håndlavede lamper

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 570 812
27 960
271 761
474
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies