Add a label to a panel or groupbox on button click - winforms

Is there a way to add a label or content to a panel/groupbox once a button has been clicked ?
So for instance, lets say I wrote some content in the above textbox and I hit Post button. Is there a way to add this content in the below panel/groupbox ? And if I can't add to a panel/groupbox, which tool should I use ?

How to Display content from a TextBox when Clicked.
Please check on your MSVC under Solution Properties for all the Buttons, Text and Panels properties. Example; Button1, TextBox1 etc. Then make functions calls and assignments by these reference.
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show(" "+ TextBox1.Text);
}
This will display your content to a Pop up window. You can also try TextBox1.Content instead of TextBox1.Text.
NB: This code should be placed on your POST button.

Related

Devexpress Popup menu with GridControl Popup menu

Where I Right-Click on GridColumn To Popup the GridColumn Menu
It Pops up with the main Popup menu
Your problem appears to be caused by PopupMenu being called all over regardless of the location of the mouse.
Use event "PopupMenuShowing" to display the user menu in GridControl. You can implement this event to decide whether to display pop-ups based on the location of your mouse.
private void gridview1_PopupMenuShowing(object sender, PoupMenuShowingEventArgs e)
{
// check in row and in cell
if(!e.HitInfo.InRow && !e.HitInfo.InRowCell)
return;
// showing main(user) popup menu
popupMenu1.ShowPopup(gridcontrol1.PointToScreen(new Point(e.Point.X, e.Point.Y)));
}

Click outside component to unfocus

By default, I need to focus on another component (a button or a textBox) to unfocus from the current one.
I want to just click outside.
So for example if I click on a textBox and write something, than click outside the TextBox, I shouldn't be able to type because the component is unfocused.
(I hope my explanation is clear, if not, please say so in the comments)
You can achieve this functionality by attaching to PreviewMouseDown event of a Window. Also in order to Lose Focus you need another focusable control (e.g. a text box named _dummyControl) to move focus to.
public MainWindow()
{
this.PreviewMouseDown += PreviewMouseDownEventHandler;
}
private void PreviewMouseDownEventHandler(object sender, MouseButtonEventArgs e)
{
//check conditions here...
_dummyControl.Focus();
}
more info:
PreviewMouseDown event occurs just before a MouseDown or click event occurs. By attaching to this event your code can tell when user clicks on the window and at that time you should move focus to a hidden control to simulate unfocus functionality.

PopUp Form in Devex

I want to display a popup form when user clicks a button. But i don't want to create a new form and display it. Is there any tool in devex that could achieve this. Currently i am using Group Control to display instead of new popup form.
Please help me. Thanx in advance
You can use PopupControlContainer class and its PopupControlContainer.ShowPopup method:
private void simpleButton1_Click(object sender, EventArgs e)
{
popupControlContainer1.ShowPopup(Cursor.Position);
}
ps: Don't confuse between PopupControlContainer class and PopupContainerControl class.
You can use a popcontaineredit which looks like a dropdown. Make this so small that you can just see the Dropdown Button at the end. Modify the Button for your needs. Then use the PopupContainerControl. This is very similar to panel. You can easily customize it for your needs (add controls on it etc.). Then you have to connect popupedit and popcontrol. Click the edit and it will popup the popupcontrol. Let me know if you need further help.

GridViewColumnHeader.Click triggered by clicking ListView's scrollbar shaft & scroll arrows

I am using attached behaviours to add the ability to sort a ListView by clicking on a column's header. The behaviour adds the following handler to handle the user clicking on a GridViewColumnHeader:
listView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click));
The handler looks something like this:
static void ColumnHeader_Click(object sender, RoutedEventArgs e)
{
var listView = sender as ListView;
var header = e.OriginalSource as GridViewColumnHeader;
var gridView = ((GridView)(listView.View));
...
}
I just noticed that if the ListView has a scroll bar, and I click on the scroll bar's 'shaft' or scroll arrows (but not thumb!):
(source: microsoft.com)
then the GridViewColumnHeader.ClickEvent is triggered, and my code fails because 'header' is now null. Obviously this isn't an expected behaviour, and now I have to make sure that the OriginalSource is a GridViewColumnHeader.
Why does this happen?
The problem is, GridViewColumnHeader.ClickEvent actually is ButtonBase.ClickEvent, which means that the handler you set will be triggered by a user click on any button (or derived: checkbox, datepicker, scrollbar button, etc.) in the ListView, and not only on a column header (which is derived from button).
See http://social.msdn.microsoft.com/Forums/en/wpf/thread/3595d153-4faa-4501-9c6f-2f074658e760
The only solution I've found is to check that header != null before doing anything else, to exit the handler when the button that triggered it (e.OriginalSource) was not a column header.
Hope this helps...
(PS: also check if header.Column != null, to avoid an error when the user clicks on the "last extra header", the empty header on the right of all the "regular" headers...)

Button simulating keyboard "Shift" key pressed

I Have a WPF window that have a RadGridView and a Button,
My requirement is, when you click on the button and
select a row in the grid, it should work similar to
pressing on the shift key and clicking on a gridview row.
(To select multiple rows).
So, i need to press the shift key programatically in button
click event.
Can this be done?
Appreciate if anyone can provide a solution
Do not fire a KeyPress event manually. Rather, on this page, Telerik indicates that to allow multiple selection, you must set the SelectionMode to Extended:
this.radGridView.SelectionMode = System.Windows.Controls.SelectionMode.Extended;
So, put this in your button click (I guess you'll want it to toggle between Extended and Single. Multiple's behaviour is awkward, but that's just me) and you're good to go.
Edit:
The toggle button will have something like this in its click event handler:
private void toggleButton1_Click(object sender, RoutedEventArgs e)
{
this.radGridView.SelectionMode = toggleButton1.IsChecked ? SelectionMode.Extended : SelectionMode.Single;
}

Resources