Contents of Windows Form do not display - visual-studio-2013

I have just started coding a simple windows form, but when I compile it the buttons/textboxes does not display.
Only a blank window pops up.

It looks like there is nothing in your InitializeComponent function.
Add this code in the function and you should see a button with "Connect" written on it.
private void InitializeComponent()
{
System.Windows.Forms.Button ConnectBtn = new System.Windows.Forms.Button();
ConnectBtn.Location = new System.Drawing.Point(10, 10);
ConnectBtn.Name = "ConnectBtn";
ConnectBtn.Size = new System.Drawing.Size(75, 23);
ConnectBtn.Text = "Connect";
this.Controls.Add(ConnectBtn);
}

Related

Xamarin.Forms Pages are merging together

When I navigate to a new page, adding it to the stack, if it is not full height of the page, it shows part of that page and part of the previous page (like a modal). I have a Xamarin.Forms app which uses a master detail page. I have upgraded to Xamarin.Forms Nuget 2.3.3.168 and am on the latest Xamarin version for Visual Studio.
I also checked the Navigation stack when going to a new page and everything looks correct. I have 1 master page which is the menu and the detail page has a navigation page with more pages in the stack, they just display partially on top of each other.
The only other thing I have changed is when I needed to initialize my App() constructor by setting the MainPage to a new MasterDetail page because it was failing if I did not do that in the constructor for Android. Any ideas?
Here is my App.cs:
public App()
{
InitializeComponent();
var masterDetailPage = new MasterDetailPage
{
Master = new Page() { Title = "Title" },
Detail = new Page(),
IsPresented = false
};
App.Current.MainPage = masterDetailPage;
}
Then, when I figure out if the user is logged in or not, I reset the master detail page with this function:
public static void SetMainPage(Page newPage)
{
var rootPage = new NavigationPage(newPage) { BarBackgroundColor = Color.White};
_nav.Initialize(rootPage);
_dialogService.Initialize(rootPage);
App.Current.MainPage = new MasterDetailPage
{
Master = new Menu(),
Detail = rootPage,
BindingContext = new MowMagicMobileViewModelBase(),
IsPresented = false
};
}
Then from there I call Navigation PushAsync() to pop a page onto the stack.
Wow it was actually that I just did not set a background color at all. I guess if you do not explicitly set it for the page it is transparent, unless that gets inherited from somewhere?
I dont know if its the solution but i have masterdetail page too..
But my page is like this
Master = new MenuPage();// it is a content page
Detail = new NavigationPage(new HomePage());
try it to see
If you want to change background i did sth like that
public class NavigationPageBase:NavigationPage
{
public NavigationPageBase (ContentPage c):base(c)
{
/*if (c.GetType().Equals(typeof(LoginPage)))
SetHasNavigationBar(c, false);
else
SetHasNavigationBar(c, true);*/
SetHasNavigationBar(c, true);
BarBackgroundColor = Styles.toolbarColor;
BackgroundColor = Styles.bgPageColor;
}
}
and for detailpage you can use it for example like
Detail = new NavigationPageBase (new HomePage ());
And from your App() constructor you can do simply
MainPage = new MyMasterDetailPage();
Hope it helps

Showing a dialog on top right corner

I want to create a dialog with a custom layout and no title. Also, the dialog should open on the top right corner of the screen. Here is the screenshot of what I want.
In xamarin.iOS is something like PopOverViewContainer. May it's in Android the same.
Maybe by changing the gravity of the dialog using the WindowManager Attributes property:
Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
AlertDialog alertName = builder.Create();
alertName.SetTitle("Warning...");
alertName.SetIcon(Android.Resource.Drawable.IcDialogAlert);
alertName.SetMessage("This is a warning message");
alertName.SetButton("OK", (s, ev) =>
{
return;
});
alertName.Show();
var window = alertName.Window;
var wlp = window.Attributes;
wlp.Gravity = GravityFlags.Top;
wlp.Flags = WindowManagerFlags.DimBehind;
window.Attributes = wlp;
You should be able to change the gravity parameter and the flags (which currently stops the background to the dialog from dimming
I have used below code to achieve my requirement.
Window window = dialog.Window;
WindowManager.LayoutParams wlp = window.Attributes;
wlp.Gravity = GravityFlags.Top | GravityFlags.Right;
window.Attributes = wlp;

How to prevent multiple instance creation by SHBrowseForFolder()?

I am developing one application and i have added one button (CButton) which is calling SHBrowseForFolder() function. But the problem is that the button is still active and also it is letting me to click my parent window. Also i can click again and again that button and multiple browsing window are coming.
What i want to know that is there any way to use SHBrowseForFolder() in a DoModal() way, so that the control did not return to the parent window till user click that Ok/Cancel button of the folder browse window? I do not want to disable that button after clicking once or something like that.
I am using Visual Studio 2010.
Thanks in advance.
Sure it's possible:
void CUtility::BrowseFolder(CWnd* pParentWnd, const CString& sTitle, CEdit& Edit)
{
LPMALLOC pMalloc = NULL;
::SHGetMalloc(&pMalloc);
TCHAR pBuffer[MAX_PATH] = {0};
LPITEMIDLIST pidlRoot = NULL;
BROWSEINFO bi;
bi.hwndOwner = pParentWnd->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = pBuffer;
bi.lpszTitle = sTitle;
bi.ulFlags = BIF_USENEWUI;
bi.lpfn = NULL;
if((pidlRoot = ::SHBrowseForFolder(&bi)) == NULL)
return;
if(::SHGetPathFromIDList(pidlRoot, pBuffer))
Edit.SetWindowText(pBuffer);
if(pidlRoot)
pMalloc->Free(pidlRoot);
}

fire a popup when ApplicationBarMenuItem clicked

I need to fire a popup when ApplicationBarMenuItem clicked. but nothing happen when I click MenuItem. here is my code;
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Go by date" Click="GoByDate_Click" />
</shell:ApplicationBar.MenuItems>
private void GoByDate_Click(object sender, EventArgs e)
{
Popup popup = new Popup();
popup.Height = 480;
popup.Width = 480;
popup.VerticalOffset = 100;
DatePopupControl datePopup = new DatePopupControl(); // just a user control comes when add new
popup.Child = datePopup;
popup.IsOpen = true;
}
Something is wrong with your DatePopupControl, because your code worked fine for my own test control. Can you provide DatePopupControl source code?
Alright, let me try to guess. My first theory is: there is nothing to show in this popup.
For example, if you add a userControl, which has only Grid tag inside without anything, you will see in the editor in Visual Studio, but it won't be visible as a popup child. But if you add a single textblock, it will be.

how to add/show a UserControl (e.g. popup) in a WP7 app page?

hi i have created a user control.
now i want to add this control to a page e.g. when the user clicks a button (important is, that i dont want to add it direcly in xaml, i want to add id in the c# code section)
how to so this?
In your button's Click event, you could do something like:
MyControl control = new MyControl();
// Set whatever properties you need in your control here
LayoutRoot.Children.Add(control);
if (listBox1.Items.Count == 0)
{
Popup popup = new Popup();
WPCpopup po = new WPCpopup(popup);
popup.Width = System.Windows.Application.Current.Host.Content.ActualWidth;
popup.Child = po;
popup.VerticalOffset = 300;
popup.IsOpen = true;
}
WPCpopup is usercontrol

Resources