Change datePicker month format in Xamarin - c#

I have a DatePicker in my application and I want to display the date in this format : 11/26/2019
So I change the Format property as follow :
myDatePicker.Format = "MM/dd/yyyy"
myDatePicker.Date = DateTime.Now;
But the display date got this format :
November 26 2019
May I have to do other things for this ?

It seems an existing issue of Xamarin.forms for UWP .As workaround, you can reset the format of DatePicker by using Custom Renderer .
in UWP project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xxx.UWP;
using Xamarin.Forms.Platform.UWP;
using Xamarin.Forms;
[assembly:ExportRenderer(typeof(DatePicker),typeof(MyPickerRenderer))]
namespace xxx.UWP
{
public class MyPickerRenderer:DatePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.MonthFormat = "{month.integer}";
}
}
}
}
I will post the issue on github immediately ,and will reply you if has any update.

Related

changing a label using a combobox and a button

hi im sorta new to doing projects myself but one of my first tasks was to make a btec grade to ucas points converter by allowing the user to select their grade from the combobox and it would show in a label the correlating grade
however i dont know how to get the selected combobox item to change the label for each different grade
i tried using a an if statement but i realised that it comes up with error CS0029
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 btec_to_ucas
{
public partial class Form1 : Form
{
string PPP = "48";
string MPP = "64";
string MMP = "80";
string MMM = "96";
string MMD = "112";
string DDM = "128";
string DDD = "144";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1 = PPP)
{
label1.Text = PPP;
}
}
}
}```
Problem is here: if (comboBox1 = PPP). In this case, comboBox1 is the whole combo box object, with its items, selected index, size, etc. That will never be equal to the string "48". You want to look at the value that has been entered. Try comboBox1.SelectedText.
See:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox?view=netcore-3.1

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();
}
}
}

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

Namespace is not working properly

I am getting a error for my namespace that says " the type or namespace name could not be found (are you missing a using directive or an assembly reference?) " and have no idea why... i have been trying to figure this one out for hours now... btw i am a newbie with c#
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using portfolioNamespace;
public partial class DefaultCode : System.Web.UI.Page{
Portfolio myPortfolio;
protected void Page_Load(object sender, EventArgs e){
//declare
myPortfolio = new Portfolio();
populate();
}
private void populate(){
//populate everything
populateMenu();
populateHome();
populateSamples();
populateAbout();
}
private void populateMenu(){
//populate the menu
String[] menu;
menu = myPortfolio.getMyMenu();
repLinks.DataSource = menu;
repLinks.DataBind();
//populates a hidden text box so i can get an array in javascript
for (int i = 0; i<=menu.Length - 1; i++){
dummy.Value = dummy.Value & menu(i) & "-";
}
}
private void populateHome(){
//populate home
homeRepeater.DataSource = myPortfolio.getHomeInfo;
homeRepeater.DataBind();
}
private void populateSamples(){
//populate samples
samplesRepeater.DataSource = myPortfolio.getSamplesInfo;
samplesRepeater.DataBind();
}
private void populateAbout(){
//populate about
aboutRepeater.DataSource = myPortfolio.getAboutInfo;
aboutRepeater.DataBind();
}
}
In your Solution Explorer Right click your References, click Add Reference > Browse, then find your dll file that contains portfolioNamespace and add it to your References.
See documentation for more details: How to: Add or Remove References By Using the Add Reference Dialog Box
You probably haven't created the portfolioNamespace.
You do so by wrapping your code in
namespace portfolioNamespace
{
//your code here
}
Have a read through these references, namespace (C# Reference) and Namespaces (C# Programming Guide)
It is not clear which file is getting error.
whatever the class name is giving error put cursor on that and press CTRL + DOT(.) it will suggest you to add the correct name space

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.

Categories