How to hide and show group of controls using Panel [duplicate] - vb.net

I am designing a multipage windows form using panels.
I'm displaying a login form and validating the button click, and want to hide the login panel and show the main panel.
However, when I click the button, the login panel disappears alright, but the main panel does not appear. since there is nothing to display, the form window shrinks to just the minimize/maximize/close buttons.
Here's the code for the button:
private void btn_login_Click(object sender, EventArgs e)
{
if (pwdBox.Text == optopwd)
{
MessageBox.Show("Good Morning!!");
loginpanel.Visible = false;
mainpanel.Visible = true;
}
else MessageBox.Show("Incorrect password!");
pwdBox.Text = "";
}
Please let me know what I have missed/misunderstood. Thanks!
Edit:
Screenshots:
Login Screen:
http://img641.imageshack.us/img641/9310/loginscreenj.jpg
Empty window:
http://img163.imageshack.us/img163/1376/emptyx.jpg

The standard mistake is that you accidentally put the mainpanel inside the loginpanel. So when you make loginpanel invisible, the mainpanel can never become visible. This accident is common in the designer, it won't let you put two panels on top of each other. You fix it with View + (Other Windows) + Document Outline. Drag mainpanel and drop it on the form. You'll have to fix the Location property by editing it in the Properties window instead of moving the panel with the mouse.
An entirely different approach is to use a TabControl. Easy in the designer, you just need to hide the tabs at runtime. Code is here.
Or use two UserControls.

Looks like your for is automatically resizing. There are 2 properties on the form responsible for auto size:
AutoSize = True;
AutoSizeMode = GrowAndShrink;
If you have the above settings then your form would shrink just to control panel (buttons) if there's nothing else to display.
Let me know if that helps.
UPDATED
also... does your control "pwdBox" belong to main panel?

Two suggestions:
Try setting the height attribute to 100%
mainpanel.Height = 100%
If that doesn't work, ensure that the page isn't initializing with mainpanel.visible set to false on a postback.

Related

Visual Basic PictureBox Panel Flicker

I am making a simple game that (for the main part) consists of a Panel with a grid of 32 PictureBoxes inside, each with a BackgroundImage. You click on a "tile" and it flips revealing a picture. My problem is that when the Form Loads, I can see it drawing. I see the Panel .. then empty PictureBoxes, then finally it fills in the PictureBoxes with the BackgroundImages.
I've turned DoubleBuffer to True for the Form, and I've also added the following:
Private Sub UseDoubleBuffer()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
Me.UpdateStyles()
End Sub
Which I call when the Form Loads. I'm not sure what else I can do? I want it to just 'pop' onto the screen. Why isn't the DoubleBuffer working? Do I need to code the panel manually? I was trying to avoid that as it's obviously easier to just drag and drop into the Form, but if I need to, I will.
I can't post screenshots apparently, as my rep isn't high enough yet, but believe me, it looks hideous, and I do want to make this as sleek as I possible can. Any ideas?
Try creating flicker free custom panel controls:
Here are the steps to use this control:
1. Add new class "NonFlickerPanel" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerPanel object instead of Panel object in your application.
public partial class NonFlickerPanel : Panel
{
public NonFlickerPanel() : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,
ControlStyles.UserPaint
ControlStyles.OptimizedDoubleBuffer,
true);
}
}
Try making the picture boxes invisible (.visible = false) until they're all loaded, then set visible to true for all of them.

Custom context menu XAML for WP8

I try to implement a custom ContextMenu in a LongListSelector.
I'm not using the ContextMenu from Microsoft.Phone.Controls.Toolkit, it's basically the same as in the Rowi App:
(source: hiddenpineapple.com)
Approach 1
My list item toggles a VisualState on hold and an overlay is shown with controls in it.
The problem
I can't find a way to go back to the default state when the user clicks outside of the list item (as in the default ContextMenu).
Approach 2
I've implemented a custom template for the toolkit ContextMenu which looks exactly the same. I had to move its margin top to -itemHeight, as by default it is below the item.
The problem
The problem with this solution is, that it automatically closes itself when opening and I couldn't figure out how to avoid this.
Another problem was that it didn't work well with TiltEffect.IsTiltEnabled from the Toolkit (visual problems).
I need your help
Any suggestions on how to get this working?
Answer
Thanks to Cheese, now I know how to properly close the menu when the user clicks outside.
His suggestion was to get the coordinates of a Tap event on the current page, and check if it's inside the menu. When not, close the menu.
So I added a Tap listener to the page when the menu opens, and removed it when the menu closes. From the page listener I got the event coordinates and could check if it's inside the control which holds the menu (same size and position). I received the position of the control with Point leftUpperPoint = control.TransformToVisual(page).Transform(new Point(0, 0)) and the rightLowerPoint by adding the ActualWidth and ActualHeight.
But then I realized:
Why should I even calculate if the tap is inside the menu? I always want to close the menu when the user taps anywhere on the screen. If it's outside, yes. If it's on a menu button, yes.
Another modification I made was to listen for MouseLeftButtonDown instead of Tap as it also triggers when the user swipes.
So I removed this code and came up with the following:
private void ToggleMenu(object sender, System.Windows.Input.GestureEventArgs e)
{
PhoneApplicationFrame frame = ((PhoneApplicationFrame)Application.Current.RootVisual);
VisualState state = this.States.CurrentState;
if (state == null || state.Name == "DefaultState")
{
frame.MouseLeftButtonDown += MouseDownDelegate;
this.State = "MenuState";
}
else
{
frame.MouseLeftButtonDown -= MouseDownDelegate;
this.State = "DefaultState";
}
}
private void MouseDownDelegate(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToggleMenu(sender, null);
}
This works perfectly!
Thanks to Cheese for the hint.
Something like this by #denniscode http://dotnet.dzone.com/articles/rowi-show-tap-menu
Approach 1 problem
The best solution would be:
Get the menus coordinates, when user makes a tap - you check are tap coordinates on menu or not, if not - dissmiss - simple.
Approach 2 problem
I guess you had some button in a corner and when you tapped on it - nothing happened? And when you dissmissed the Tilt all worked. It seems that tilt works faster than a click, so, tilt changes the button coordinates, and device thiks you have missed/or dragged off
You can use what #ScottIsAFool suggested and maybe create another Dependency Property on your TapMenu control of type UIElement named CloseWhenTappedElement and automatically listen for Tap events inside your control once set. For example
<Grid x:Name="TapArea"/>
<TapMenu CloseWhenTappedElement="{Binding ElementName=TapArea"}/>

VB.NET never get focus on any control

i have developed a simple calculator like in windows calculator,
but unlike in windows calculator, after clicking any button, the focus on that button is still there on the particular clicked button.
so how to never get focus for all buttons on calculator form ... ?
i don't think that it will better to write loose focus code on every button's click event ... so any better solution ?
Without seeing any code of yours, I am going to assume that you have a text box that displays the numbers pressed by the user, so you need to set the focus to the text box once a user clicks a button, like this:
TextBox1.Focus()
Note: If your text box is not named TextBox1, then change the name to whatever your text box is actually named.
Instead of a standard button use an instance of a NoFocusButton class derived from the Standard button. In this class override the ShowFocusCues property and return always false.
Form f = new Form();
// Need to add manually the buttons to your form unless you build a customcontrol
NoFocusButton b = new NoFocusButton();
b.Text = "ClickMe";
f.Controls.Add(b);
f.Show();
// Class derived by the Button control, it is identical but the
// property that control the drawing of the Focus rectangle returns FALSE
// tricking the WinForm system to avoid to draw the focus rectangle
class NoFocusButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
The credit goes to Remove Focus Rectangle from Button

Windows 8 appbar on selected item (like startup screen)

What I want to achieve in my application is the same as what windows did on their start up screen. When you select an item, open the appbar and show more items. When you just open te appbar when not selecting anything, don't show those items.
So far so good and it works like I want it to be. But there is some issue I can't solve. When you select an item on the start up screen, you can't close te appbar when right clicking anywhere on the screen. You have to deselect the item.
I just can't figure out how to disable that right click to close the appbar. Because then I am in a state where I have a selected item, but no appbar. I don't want that...
Thanks in advance!
There is a property called IsSticky
this can be used to stop you appbar from collapsing.
the other option you have is to hooking into Closed event and force it to re-open.
Based on the screen you provided aka the Metro UI :) i'd say that create a page that just hosts other tiles.
I have done a similar thing in one of my apps, have a look at
http://apps.microsoft.com/windows/en-gb/app/cineworld/7adfde16-33c3-4b51-b758-00366325288d
Have a look at Coding4Fun or Callisto
Set the AppBar property IsSticky="true" and handle the event RightTapped on your GridView/ListView, and in the event handler set e.Handled = true;
This will stop the rightclick/swipe routed event from reaching Page and it won't close the AppBar.
You could override the hide() function of the appbar and replace it with something like this:
appBar.hide = function () {
/// <signature helpKeyword="WinJS.UI.AppBar.hide">
/// <summary locid="WinJS.UI.AppBar.hide">
/// Hides the AppBar, if visible, regardless of other state
/// </summary>
/// </signature>
// Just wrap the private one
var listView = document.getElementById("yourListView").winControl;
var count = listView.selection.count();
if(count <1)
this._hide();
}
It's not a great workaround, but it works like a charm :)

How to hide a control from the form while designing in visual studio?

I am designing a settings form for my application as shown below:
A tree view with multiple nodes at the left and I want to have one GroupBox for each node to be displayed at the right whenever a node is selected. I have designed my group box with necessary controls for the first node. The question is, how do I design an another group box in the same place when another item is already there. Is there a way to hide a control from a form during design time?
I have always just changed the Z-Order of the GroupBox or Panel by right clicking on it and sending it to back. Just make sure when you add the other GroupBoxes that you add them to the same Parent. Make their Visible property False and then display the GroupBox you want at runtime by making it Visible.
EDIT: Changed answer to be more relevant.
EDIT #2: I missed the VB tag, translating this should be a trivial task anyway.
If you extend GroupBox like this, you'll have a stock GroupBox which will hide itself at design time.
public class myGroupBox : GroupBox
{
public myGroupBox() { InitializeComponent(); }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (DesignMode) this.Visible = false;
}
}
NOTE: This should work for almost any non-sealed control.