I'm trying to make a WinForm app with a expandable menu. I'm trying to create a method that will change a panel propierties in form1 but it sees the value as false even if it is not? I got message box with "recognition as false". Instead of code I would rather a nice explanation
private void JobSelectButton_Click(object sender, EventArgs e)
{
//button to open a panel with "menu"
if (jobPanel.Visible == false)
{
// the panel is visible from this point
jobPanel.Visible = true;
}
else
{
jobPanel.Visible = false;
}
}
public void fla(bool flag)
{ //method inside form1 and it should make jobPanel.Visible = false
if (jobPanel.Visible == false)
MessageBox.Show("recognition as false");
else jobPanel.Visible = false;
}
private void notification_MouseClick(object sender, MouseEventArgs e)
{ // user control that will call the method
caseNBvalue = lbl_caseNB.Text;
profile f2 = new profile();
f2.fla(true);
}
Related
i'm working on a project with C# and i'm occurring a problem while hiding a panel with (BunifuTransition) framework.
so basically i have many buttons as(Menu Buttons) and a subpanel with buttons as (submenu) and i'm having this problem...
So in here you can see that the Show and Hide panel works fine with all the clicked buttons...
Working fine in here
But when i try to close the same panel with clicking on the same button that shows it, here is what happened...
The panel closes but without Bunifu Animator
Here is the codes you need to know
private void HideSubMenu() //Method to hide the subpanles (BunifuAnimator)
{
if (PanelOtherRulesSubMenu.Visible == true)
PanelSubMenuAnimation.HideSync(PanelOtherRulesSubMenu);
}
--------------
private void ShowSubMenu(Panel Submenu) //Method to show the subpanels
{
if (PanelOtherRulesSubMenu.Visible == false)
PanelSubMenuAnimation.ShowSync(PanelOtherRulesSubMenu);
if (Submenu.Visible == false)
{
HideSubMenu();
Submenu.Visible = true;
}
else
Submenu.Visible = false;
and in here you can see that all the buttons are invoked to hide the subpanel, with exception of the "Other Rules", it is invoked the show the subpanels with some coditions ...
private void btnGovermentRules_Click(object sender, EventArgs e)
{
HideSubMenu();
}
private void GangRules_Click(object sender, EventArgs e)
{
HideSubMenu();
}
private void btnBusinessRules_Click(object sender, EventArgs e)
{
HideSubMenu();
}
private void btnBuildingRules_Click(object sender, EventArgs e)
{
HideSubMenu();
}
private void btnSubMenuOR_Click(object sender, EventArgs e) //here is the button invoked to show the panel
{
ShowSubMenu(PanelOtherRulesSubMenu);
}
And now guys i need you to help make the closing animation work as well when clicking "btnSubMenuOR_Click" button to close the subpanel.
Thank you,
Problem solved!.I just tried to remove and replace some lines of code as showing below, from this:
private void ShowSubMenu(Panel Submenu) //Method to show the subpanels
{
if (PanelOtherRulesSubMenu.Visible == false)
PanelSubMenuAnimation.ShowSync(PanelOtherRulesSubMenu);
if (Submenu.Visible == false)
{
HideSubMenu();
Submenu.Visible = true;
}
else
Submenu.Visible = false;
to this:
private void ShowSubMenu(Panel Submenu)
{
if (PanelOtherRulesSubMenu.Visible == false)
PanelSubMenuAnimation.ShowSync(PanelOtherRulesSubMenu);
else
PanelSubMenuAnimation.HideSync(PanelOtherRulesSubMenu);
}
In my application, I have a form with two panels. Inside one panel is a button. Inside the other is a DevExpress Grid control. The grid is made up of 3 columns. You can drag values from one column into the other to copy it.
My problem is that whenever I do a drag-and-drop from one column to another, the focus on the application goes into an unusual state. The grid remains focused; I can mouse over the headers and see them react as normal. However the rest of the application is not focused. Mouse over the button in the other panel does not react, nor do the menus or form controls. If I click on the button, it reacts like I clicked on an unfocused application. I have to click again to actually activate the button. Same for every control except the grid.
I have tried using Activate() and Focus() on the button and form but to no avail.
namespace Company.StuffUploader
{
public partial class ComputationGrid : DevExpress.XtraEditors.XtraUserControl
{
private BindingList<ComputationLinkModel> _links = new BindingList<ComputationLinkModel>();
public List<ComputationLinkModel> ComputationLinkModels
{
get
{
return new List<ComputationLinkModel>(_links);
}
}
public ComputationGrid()
{
InitializeComponent();
}
private void ComputationGrid_Load(object sender, EventArgs e)
{
_gridControl.DataSource = _links;
}
private DragDropEffects GetDragEffect(DragEventArgs e)
{
var text = e.Data.GetData("System.String") as string;
if (text == null)
return DragDropEffects.None;
var link = GetLinkFromScreenPoint(new Point(e.X, e.Y));
if (link == null)
return DragDropEffects.None;
var tokens = text.Split('\t');
if (tokens.Count() != 2)
return DragDropEffects.None;
var dateString = link.movedate.ToString("yyyy-MM-dd");
if (link.StuffSurfaceName == tokens[0] && dateString != tokens[1])
return DragDropEffects.Move;
else
return DragDropEffects.None;
}
private ComputationLinkModel GetLinkFromScreenPoint(Point screenPt)
{
var pt = _gridControl.PointToClient(screenPt);
var hitInfo = _gridView.CalcHitInfo(pt);
return _gridView.GetRow(hitInfo.RowHandle) as ComputationLinkModel;
}
private void _gridControl_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
var hitInfo = _gridView.CalcHitInfo(e.Location);
if (hitInfo == null || !hitInfo.InRowCell)
return;
// Only allow dragging from target column
if (hitInfo.Column.AbsoluteIndex != 0)
return;
var link = _gridView.GetRow(hitInfo.RowHandle) as ComputationLinkModel;
if (link == null)
return;
var item = string.Format("{0}\t{1}", link.StuffSurfaceName, link.movedate.ToString("yyyy-MM-dd"));
DoDragDrop(item, DragDropEffects.Move);
}
}
private void _gridControl_DragOver(object sender, DragEventArgs e)
{
e.Effect = GetDragEffect(e);
}
private void _gridControl_DragDrop(object sender, DragEventArgs e)
{
}
private void _gridControl_DragEnter(object sender, DragEventArgs e)
{
e.Effect = GetDragEffect(e);
}
private void _unlinkButton_Click(object sender, EventArgs e)
{
}
}
}
I figured out my own problem. Calling DoDragDrop() from within MouseDown event does not seem to work correctly. The proper way is to call it from MouseMove(). The documentation on MSDN hints at this in its example code.
Ensure that you set the DXMouseEventArgs.Handled property to true in the GridView's Mouse~ event handlers. It guarantees that default handling of these events will be prohibited. Review this example to see how to do this.
I've got a couple of Controls linked as follows:
ProductSearchControl (UserControl) [contains SearchProducts()]
--ProductListControl (UserControl)
--ProductResultPanel(UserControl)
|
|
|
ProductDetailsWindow (Window)
Within ProductResultPanel.xaml.cs, the following method gets called on a Button click.
void OnModifyPrice(object sender, RoutedEventArgs e)
{
if (this.ModifyPrice != null)
{
ProductDetailsWindow win = new ProductDetailsWindow(this.productId);
win.ShowInTaskbar = false;
win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
win.Owner = Window.GetWindow(this);
bool? result = win.ShowDialog();
}
}
On the ProductDetailsWindow, if I click on a Button, I want to execute the SearchProducts() within ProductSearchControl but I'm currently having difficulty.
Within ProductDetailsWindow.xaml.cs
private void OnCancel(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
private void OnSave(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
So after clicking the Save button, I am returned to ProductResultPanel but I don't know how to call the SearchProducts().
Is this possible and if so, any help would be appreciated?
The Window still exists, even after you close it, and you can access its public properties and methods from ProductResultPanel.xaml.cs. Example:
var x = win.SomePublicProperty;
var y = win.GetProducts();
// whatever you need and provide access to in ProductDetailsWindow
I want to show another form(Form2) with button click. Basically When the button is clicked in Form1, another form(Form2) should show, this should not hide the Form1 though and should change the button text to "Hide Progress" in Form1. And when this button is clicked again the Form2 should hide and the text in button should change to "Show Progress".
Below is my effort to make this work. When I clicked the Show Progress Button, it brings the Form2 and changes the text in button as well. But when I clicked the button again instead of hiding the Form2, it opens another instance of Form2.
Probably reason behind is that, the bool value is not saved.
Here is my code for button event handler.
public partial class Main : Form
{
public string output_green, output_grey, output_blue, output_black;
public bool visible;
private void button1_Click(object sender, EventArgs e)
{
output progressWindow = new output();
if (visible == false)
{
progressWindow.Show();
button1.Text = "Hide Progress";
visible = true;
}
else
{
progressWindow.Show();
button1.Text = "Show Progress";
visible = false;
}
}
}
How can I achieve that I need to.
Problem:
Each time you click button1 a new progressWindow has been initialized.
Also you are using progressWindow.Show() instead of Hide() in else part.
Solution:
Declare progressWindow out of button1_Click. And then initialize it from button1_Click. Now it will be initialized only once (using if).
output progressWindow = null;
private void button1_Click(object sender, EventArgs e)
{
if(progressWindow == null)
progressWindow = new output();
if (button1.Text == "Show Progress")
{
progressWindow.Show();
button1.Text = "Hide Progress";
}
else
{
progressWindow.Hide();
button1.Text = "Show Progress";
}
}
}
For a shorter solution where the progress window's lifetime persists with the main form :
output progressWindow = new output();
private void button1_Click(object sender, EventArgs e)
{
progressWindow.Visible = !progressWindow.Visible;
button1.Text = (progressWindow.Visible) ? "Hide Progress" : "Show Progress";
}
Here you get rid of the need for the extra boolean since the progress form itself is fully capable of telling you whether it is visible or not.
// Creates a single instance only it it is request.
private Output ProgressWindow
{
get
{
return progressWindow?? (progressWindow= new Output(){Visible = false};
}
}
private Output progressWindow;
private void button1_Click(object sender, EventArgs e)
{
ProgressWindow.Visible = !ProgressWindow.Visible;
button1.Text = (ProgressWindow.Visible) ? "Hide Progress" : "Show Progress";
}
}
I'm messing around trying to make a tictactoe game and am wondering how to use this method I created to alter the text of a button.
private void Click()
{
if (player1 == true)
{
player1 = false;
player2 = true;
this.Text = "X";
}
if (player2 == true)
{
player1 = true;
player2 = false;
this.Text = "O";
}
}
private void button1_Click(object sender, EventArgs e)
{
Click();
}
So I want to be able to change the text of the buttons, I found out that this relates to the actual form. I couldn't find any ways to assign the text to different buttons only if you are specific. Cheeeeers.
"this" is your form. You need to assign your text to button.Text.
Since your are writing a tic-tac-toe you could use the same event for all buttons :)
private void button1_Click(object sender, EventArgs e)
{
var button = (Button) sender;
button.Text = "X";
}
You could add the button1 as a parameter to your click event, like:
private void Click(Control control) {
if (!string.IsNullOrEmpty(control.Text)) {
// invalid button clicked (has already x or o)
return;
}
control.Text = player1 ? 'X' : 'O';
player1 = !player1;
player2 = !player2;
}
and then use the click event as:
private void GeneralButtonHandler(object sender, EventArgs e)
{
Click(sender as Control);
}
after which you could attach all buttons to this GeneralButtonHandler
and if you need more ideas for the game, you could find a javascript implementation here