C#: components cannot show on Windows Form - winforms

I have created an empty project. after that, I added new items is Windows Form and add some component such as button or textbox in Design View.
In main file, I use this code:
SimpleForm form = new SimpleForm(); // SimpleForm is my class
form.Show();
But, when I run, C# generate a form but I cannot see textbox nor button. I just see blank area where I put those components. As picture below, the white area is my button, but I don't know why this button cannot show. I think maybe some problem, and those components cannot draw on the form.
Please help me this error.
Thanks :)

If by "the main file" you mean your main method (the entry point) - try this code instead:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SimpleForm());
If not you really need to post more of your code to get a reasonable answer.

Related

Codename One nested Sidemenu

I am trying to create a nested side menu for a CN1 application, similar to the one in the screenshot.
For the nested sidemenu to work, I image it has to stay open when the user presses a command of a dropdown list , so that he/ she can choose an option.
But the CN1 sidemenu appears to close every time and I couldn't find a workaround.
One approach I was trying was to add an action event to the "hamburger menu ", but this doesn't seem to work.
Button sideBtn = (Button)((BorderLayout)bar.getLayout()).getEast();
sideBtn.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
Toolbar.setPermanentSideMenu(true);
};
Neither does adding Toolbar.setPermanentSideMenu(true) to any other button's action event.
Anther approach I have in mind is to add hidden buttons to the sidemenu and repaint the toolbar when the button is clicked, but this still does not keep the sidemenu open and seems to be not very direct.
Is there anything more straightforward? What would be the best approach?
Thanks in advance for any kind response.
The setPermanentSideMenu method is designed for tablets and not for what you are trying to do. Toggling it after the init(Object) method was invoked doesn't make sense and might break your app.
You didn't list how you added the button to the side menu but adding it using addComponentToSideMenu(Component) should work (notice I didn't use the version that accepts a Command).

imagelist images not available in child form .net winform

I have a dll that contains a form that is being inherited by other forms. The parent form has an imagelist with several images in it and two of these are being used in toolbar buttons. It has been working for a long time but I had to add a toolbar button and an image to go with it.
The new button with the new image displays in the designer correctly in the base form, but in an existing child form, the button doesn't display in the toolbar in the designer (although it shows up at runtime with no image). In the child form, the imagelist is present with all the original images, but the new image that I added to the base form does not appear in it.
I have tried several different icons with the same result. Interestingly when I point the new tb button to one of the images that has always existed, everything is fine in the child. It just won't handle any of the new images (I've tried icons & bitmaps). I would try to delete the toolbar and imagelist and re-create it but unfortunately I don't know where the existing images are located to be able to add them back to the new imagelist.
(VS 2010, VB.NET - but C# answers are most welcome!)
I have the same problem. My parent form have an image list wich I use to present my own control box (min, max, close). All the child forms inherit from this form and everything is ok if I don't change the elements of the list. But when I add an element or change the Image index of the control buttons, this is not reflected in the child forms. Sadly I haven't fixed it yet but what I did is:
Declare the Image list as public in the designer of the parent form
Determine the forms that don't reflect the desired change
Set Manually the desired change by adding the image to the inherited IMageLIst and changing the image index in all and every form with the bug
This is not what I intended to do by designing a parent form, but it works.

Combobox clearing value issue

I've stumbled on an issue with Comboboxes in javafx2.2. This is the scenario:
Users click on the 'editFile' button.
Another pane becomes visible (with the setVisible method).
This pane contains 6 comboboxes.
Three of them have fixed items: cboReport, cboSales, cboSend. Three of them get their data from a db (ObservableList) and get populated when the pane becomes visible: cboFile, cboCustomer, cboVet
The user selects a file number from the cboFile. The rest of the comboboxes are beeing set with the correct values.
The user presses the save button, the file gets saved as intended.
Next the user presses a close button.
When the window closes, the data on the pane gets resetted through a resetGUI_editFilePane() method. There is have lines like:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
When the user opens the pane again by pressing the 'editFile' button I notice that only the 'fixed item' comboboxes have cleared their selection, the dynamicly filled comboboxes show the last selected item although the value from the selection itself is null. This looks like a graphics bug to me or am I doing something wrong?
Is there any way around this issue or what is the best method to reset a combobox?
EDIT 2014/08/27:
This is officially not a bug(clearSelection() does not clear value):
https://bugs.openjdk.java.net/browse/JDK-8097244
The official "workaround" is to clear the value of the ComboBox after clearing selection.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
It is very simple. You just need to work with the value property of ComboBox. here you go ....
ComboBox c;
c.valueProperty().set(null);
I hope this works for you :-D
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
cboVet.getSelectionModel().clearSelection();
cboVet.getItems.clear();
do something like this...
parentNode.getChildren().remove(cboVet);
cboVet = new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(cboVet);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
You can retrieve the items and have them all removed:
cboVet.getItems().removeAll(cboVet.getItems());
I've just tested a working solution with the Java JDK 1.7.11:
combobox.setSelectedItem(null);
combobox.setValue(null);
Hope it helps :)
I use reflection with direct manipulation of buttonCell field in ComboBox skin:
#SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> void resetComboBox(ComboBox<T> combo) {
Skin<?> skin = combo.getSkin();
if(skin==null){
return;
}
combo.setValue(null);
Field buttonCellField;
try {
buttonCellField = skin.getClass().getDeclaredField("buttonCell");
buttonCellField.setAccessible(true);
ListCell buttonCell = (ListCell) buttonCellField.get(skin);
if(buttonCell!=null){
StringProperty text = buttonCell.textProperty();
text.set("");
buttonCell.setItem(null);
}
} catch (NoSuchFieldException
| SecurityException
| IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
I think it's also possible by providing your own buttonCell implementation through buttonCellFactory property
I had the same problem with a ComboBox. The buttonCell of the ComboBox is not updated correctly when I change the items of the ComboBox. This looks like a graphics bug.
I use direct manipulation of buttonCell field in ComboBox.
combo.getButtonCell().setText("");
combo.getButtonCell().setItem(null);
This is the best solution I've found without recreate the ComboBox.
To clear SelectionModel I found nothing better than creating a new instance of Combobox (previous answers update):
myParentNode.getChildren().remove(myCombobox);
myCombobox = new ComboBox();
myParentNode.add(myCombobox);
But this solution evolves other problems: if you use fxml, this combobox will be placed in the wrong place and with wrong parameters. Some fxml parameters are hardly reproduced directly from your controller class code and this is awful to do it every time you need to clear the combobox.
The solution is using custom components instead of creating instances directly in main controller class code, even if these components are standard. This also helps to free some lines in your main controller class by moving component related event methods and other methods to a separate class file, where you use a reference to your main controller class.
How to create custom components in JavaFX FXML Application can be found in http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm , but note that CustomControlExample class is not needed for every custom component in your application, if it already has an entry point class with start(Satge stage) method.
How to resolve possible errors with reference from custom component controller class to main controller class can be found in JavaFx: how to reference main Controller class instance from CustomComponentController class?
I need to clear selection of the combo box. And this code worked for me:
List<Object> list = new ArrayList<>(comboBox.getItems());
comboBox.getItems().removeAll(list);
comboBox.getItems().addAll(list);

In my Windows Phone app,I want to turn my current page unable in gray and show a textbox in foreground

Like the title said,how may i turn the grid(or page) and the components in it into background gray and unable and show a new component in foreground.
It's a common effect in the web page,but i cannot do that with a xaml.
Please answer in detail better with sample code if you do.Thanks in advance.
Here's an example of using a Popup to display a UserControl when a Page is navigated to. The OnNavigatedTo function creates a popup, binds a Click event to the UserControl, and then shows the UserControl over the entire page. If the correct password is entered, ("password" in the example) the control disappears. You'll need to modify it for your own requirements, but it should definitely get you started.
https://skydrive.live.com/redir.aspx?cid=ef08824b672fb5d8&resid=EF08824B672FB5D8!343
You'll want to use the VisualStateManager and create some animation transitions to switch between the old and new components. I won't paste the code here for brevity, but if you check out:
http://visualstudiomagazine.com/articles/2011/07/22/wcmob_visual-states.aspx
You'll see a simple example of switching between two UI components on a single page within a Windows Phone 7 PhoneApplicationPage. In your scenario, you'd use this paradigm to create 2 animation storyboards, one for showing an overlay control and one for settings the 'disabled' property on the main grid.

Move one form to another winforms - C#

I have 2 winforms Form 1 and Form 2. I have button1 in form1, when i click on button1 from form1 i display form2.
Form2 ins = new Form2();
ins.MdiParent = this.MdiParent;
this.Hide();
ins.ShowDialog();
I hide the form1 to display form2 when button1 is clicked. This creates a flicking effect and i need to remove this flicking. How do i open/redirect to another form (i am supposed to show only one form at a time and am not supposed to show any top menu like (if i use MDIParent form). Just one active form.
Thanks,
Karthick
It sounds a bit like you're trying to create a web-style UI where the user steps from one "page" (represented by a Form) to another.
Rather than implementing a UI like this with separate forms, you're better off doing it with UserControls hosted on a single parent form.
Have a read of this MSDN article, which includes a download with sample code. It's a great walkthrough for designing that kind of user interface:
IUIs and Web-Style Navigation in Windows Forms, Part 1
IUIs and Web-Style Navigation in Windows Forms, Part 2
Edit
If you're intent on showing two separate forms, is there any reason you need to show the second one modally? Can you not simply show it and then hide the original?
form2.Show();
form1.Hide();
... or do you have yet another form that both form1 and form2 are "modal" to?
To transfer from one page (form1) to another (form2)
suppose form1 contain a button named "SAVE"
we have to write the following code in click event of the "SAVE" button
form2 f2=new form2();
f2.Show();
I think there is a property on winforms if you would like to show it on the task bar or not.
I can clarify your doubt about how to redirect from one form1 to form2
for example:
place a link in form1 and then write following code in it
form2 ins=new form2();
ins.show();
Instead of hide use close option.
Form1 formObject = new Form1();
formObject.Close();
or simply
this.Close();

Resources