UWP - CheckBox or Button is not visible - c#

Using
Jetbrains Rider
Universal Windows Platform
Problem
The window is visible, but the buttons are not visible.
Question
How can I fix the problem?
Source code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace UWP_TEST1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
StackPanel stackPanel1 = new StackPanel();
CheckBox checkBox1 = new CheckBox();
checkBox1.Content = "I agree to the terms of service.";
stackPanel1.Children.Add(checkBox1);
}
}
}

You forgot to add the StackPanel stackPanel1 to the page. Setting the content of your page to the stackPanel1 will show the buttons. You can do this by adding Content=stackPanel in the constructor.

Related

How to display Filenames in gridview on the basis of date selected from two calendar controls (DateFrom to Dte to) in asp.net c#

How to display Filenames in Gridview on the basis of date selected from two calendar controls (DateFrom to DateTo) in asp.net c#. I have Gridview control and Two calendar controls. when user will select Dates in calendar control i want to display stored files in the Gridview between selected months range.
Try following :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication24
{
public partial class Form1 : Form
{
const string FOLDER = #"c:\temp";
public Form1()
{
InitializeComponent();
dateTimePickerStart.Value = DateTime.Parse("1/1/2017");
dateTimePickerEnd.Value = DateTime.Now;
string[] files = Directory.GetFiles(FOLDER).Where(x => (File.GetLastWriteTime(x) >= dateTimePickerStart.Value) && (File.GetLastWriteTime(x) <= dateTimePickerEnd.Value)).ToArray();
}
}
}

Dataset not recognized in new form

I have used my Dataset all over the project without any problem.
When I Add a new form , the Dataset is not recognized in it - JUST THE NEW FORM.
It says :
The name 'mydataset' does not exist in the current context
I have checked using System.Data.SqlServerCe; using System.Data.SqlClient; is in the form.cs.
I tried to declare new one in form.cs and it doesn't work.
form.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
namespace O2
{
public partial class ProductSelect : Form
{
public ProductSelect()
{
InitializeComponent();
}
private void ProductSelect_Load(object sender, EventArgs e)
{
//DatabaseDataSet ds = new DatabaseDataSet();
foreach (DataRow row in mydataset.Products.Rows)
{
listBox1.Items.Add(row["Product_Name"]);
}
}
}
}
Any help ?
Edit :
form2 where mydataset works perfect (without declaring it) :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
namespace O2
{
public partial class SalesBill : Form
{
public SalesBill()
{
InitializeComponent();
}
private void SalesBill_Load(object sender, EventArgs e)
{
foreach (DataRow row in databaseDataSet.Clients.Rows)
{
listBox1.Items.Add(row["Client_Name"]);
}
}
}
}
If you are using the designer for configuring the form and elements on it, from toolbox in Data section, drag an DataSet and drop it on form. You can select either typed dataset or untyped dataset
If you want to create and use dataset from code, consider declaring your dataset variable and create an instance of your typed or untyped dataset.
open form 2 at designer you probably will see a component with name databaseDataSet in component tray of it. It seems you are using a typed dataset.
And if you look at Data Source window (Shift+Alt+D) you will see a node of DatabaseDataset with some child node that are your tables.
You can drag clients table and drop it on form.
In .NET you declare a dataset like this:
DataSet myDataSet = new DataSet();
You can declare DataSet as global
public static readonly DataSet MyDataSet = new DataSet();
And access in other forms as
CLassName.MyDataSet; // ClassName is that in which you declare your dataset
But the recommended way is that, you need to add DataSet from toolbox or from new item dialog and add required tables into it.

How to copy only numbers from masked textbox to a label?

I made a masked textbox for saving numbers with the mask (999) 000-0000 and I want to show only numbers in label but when I do that, it also copies the parantheses and lines.
I know it copies all the text. How I can only copy numbers entered not with mask?
(windows form)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = maskedTextBox1.Text;
}
}
}
One solution is to set TextMaskFormat to ExcludePromptAndLiterals just before reading it's value:
maskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
Console.WriteLine(maskedTextBox1.Text);
//will print 3123 when value in the mask textbox is (31) 23 for mask (00) 00
And after this set Format back:
maskedTextBox1.TextMaskFormat = MaskFormat.IncludeLiterals;
Even if you won't set format back to IncludeLiterals, UI control still would show masked text (31) 23 and will work as usual. This is done if your other logic relies on masked Text field.
So if you don't have such dependencies, you can set this value right in the Visual Studio designer in properties window for maskedTextBox1

Custom control error

I am working on this custom control. (I am very new to this part of programming.) I am working on an application that has to be able to format mathematical expressions as the user enters the input in my own custom control. This is how I want the control to look like (this image is made in Photoshop):
I will not explain the behavior I want it to have, because this doesn't help you, but the idea is that it is not based on any Windows Control.
Tis is the code I already have:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Support.Components
{
public partial class PartialExpressionEditor : Control
{
public PartialExpressionEditor()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Brush background = Brushes.White;
pe.Graphics.FillRectangle(background, ClientRectangle);
background.Dispose();
}
}
}
When I try to put it in my form, I get this error dialog:
Where is the problem? Or why this error appears?
I think the problem is that you are disposing a system brush:
// background.Dispose();
since you didn't create it:
Brush background = Brushes.White;
To use your own brush that you dispose yourself:
using (SolidBrush br = new SolidBrush(Color.White)) {
pe.Graphics.FillRectangle(br, this.ClientRectangle);
}
You might have to exit Visual Studio to get your Brushes.White brush back.

Where are the Properties gone ? I did Properties.Resources but properties not exist

This is the code in my class i have:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
namespace Magnifier20070401
{
public partial class MagnifierForm : Form
{
public MagnifierForm(Configuration configuration, Point startPoint)
{
InitializeComponent();
//--- My Init ---
mConfiguration = configuration;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = mConfiguration.ShowInTaskbar;
TopMost = mConfiguration.TopMostWindow;
Width = mConfiguration.MagnifierWidth;
Height = mConfiguration.MagnifierHeight;
// Make the window (the form) circular
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mImageMagnifier = Properties.Resources.magnifierGlass;
On the Properties im getting: Error 1 The name 'Properties' does not exist in the current context
I added this Form as Existing item to my project and im getting an error on this Properties.
And i have the magnifierGlass image in the Resources.
Found it needed to add my project name before the properties:
mImageMagnifier = ScreenVideoRecorder.Properties.Resources.magnifierGlass;
Now it's working thanks.

Categories