I am following a Xamarin Example with my code:
public App()
{
InitializeComponent();
DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged;
}
void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e)
{
var displayInfo = e.DisplayInfo;
}
As far as I can see this is just the same as in this example:
https://learn.microsoft.com/en-us/xamarin/essentials/device-display?context=xamarin%2Fios&tabs=uwp
But it is giving me the error message:
App.xaml.cs(13,13): Error CS0123: No overload for
'OnMainDisplayInfoChanged' matches delegate
'EventHandler' (CS0123)
Can anyone help explain to me what this error message means and let me know if there is a way for me to fix this?
This error is coming because you missing first param that is object sender. Try to pass full method signature.
private void OnMainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
{
var displayInfo = e.DisplayInfo;
}
Related
I'm trying to pass a program name from my form to a button click event. But I keep getting the following error message:
"No overload for “method” matches delegate 'EventHandler' "
I've read up on similar problems here and tried numerous suggestions but nothing seems to fix my specific problem. I'm hoping someone can tell me where I'm going wrong. Here are some of the posts I've read:
No overload for 'method' matches delegate 'System.EventHandler'
C# CS0123: No overload for matches delegate Eventhandler
Error - No overload for "method" matches delegate 'System.EventHandler'?
I don't seem to have a clear understanding of how to match up the signatures of my event methods. The documentation I've read hasn't helped. Any assistance from a knowledgeable person would be greatly appreciated.
My code is as follows:
using System;
using System.Windows.Forms;
namespace ProgramOne
{
public partial class frmLogin : Form
{
public frmLogin(string pgmName)
{
InitializeComponent();
Click += (sender, EventArgs) => { BtnSubmit_Click(sender, EventArgs, pgmName); };
}
private void BtnSubmit_Click(object sender, EventArgs e, string pgmName)
{
txtUserId.Text = txtUserId.Text.Trim();
txtPassword.Text = txtPassword.Text.Trim();
if (txtUserId.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Please provide a valid UserID and Password");
return;
}
bool securityCheckPassed = true;
if (securityCheckPassed)
{
//Open new form
MessageBox.Show(frmLogin.pgmName);
}
}
}
}
LarsTech and Chetan Ranpariya provided excellent suggestions that helped me solve this problem. My solution appears below for other C# newbies like me to use:
using System;
using System.Windows.Forms;
namespace ProgramOne
{
public partial class frmLogin : Form
{
private string pgmName; <-- Declare the variable
public frmLogin(string pgmName)
{
InitializeComponent();
this.pgmName = pgmName; <-- Initialize with passed value
}
private void BtnSubmit_Click(object sender, EventArgs e) <-- Remove pgmName from original code above
{
txtUserId.Text = txtUserId.Text.Trim();
txtPassword.Text = txtPassword.Text.Trim();
if (txtUserId.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Please provide a valid UserID and Password");
return;
}
bool securityCheckPassed = true;
if (securityCheckPassed)
{
//Open new form
MessageBox.Show(pgmName); <-- Access the name
}
}
}
}
The program name now shows up in the BtnSubmit_Click event handler for me to use to launch subsequent forms as needed. Just replace "MessageBox.Show(pgmName);" with "GoToForm(frmName);" (replacing the sample name values with your own names).
I have started a new job, where the last dev left they want a program he started to be finished .
I have got to this problem and have looked at it for half a day.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
logTimer = new System.Windows.Threading.DispatcherTimer();
logTimer.Tick += new EventHandler(logTimer_Tick);
logTimer.Interval = new TimeSpan(0, 0, 0, 1);
logTimer.Start();
txtLogData.Text = Logger.GetLines();
try
{
DataProcessor gaugeProcessor = new DataProcessor(SQLConnectionString);
gaugeProcessors.Add(gaugeProcessor);
grdProcessor.ItemsSource = gaugeProcessors;
List<GaugePort> ports = SQLClient.GetGaugePorts(SQLConnectionString);
foreach(GaugePort port in ports)
{
GaugePortListener newListener = new GaugePortListener(port);
listeners.Add(newListener);
}
grdPorts.ItemsSource = listeners;
}
catch(Exception ex)
{
}
}
I am getting an error on line 4 "No Overload for ' logTimer_Tick' matches delegates 'Event Handler'"
The Function it calls dose exist and looks like this
private void logTimer_Tick(object sender, EventArgs e)
{
txtLogData.Text = Logger.GetLines();
}
I have had a look at the links below but i have drawn a blank
http://www.yoda.arachsys.com/csharp/threads/parameters.shtml
C# method name expected
Any ideas would be great
Thanks in advance
EDIT
Change the wording for the error message "Typo"
Directly use the method:
logTimer.Tick += logTimer_Tick;
This should help, as the compiler does strange things with your EventHandler.
The weird thing is that your code seems to work on my machine - that means the code you posted isn't equal to the code you tried or it's a bug caused by your compiler. Or, as a third possibility, the logtimer isn't a WinForms timer, then I can't reproduce your problem.
In this third case it may be possible that the second parameter isn't an EventArg (even though it'd be strange that it works if you don't use the EventHandler stuff). Then you could try an object as second parameter:
private void logTimer_Tick (object sender, object e)
It seems to be neccessary for Windows phone 8.1 (No overload for 'method' matches delegate 'System.EventHandler').
Here is my code:
public void RemovalWorker_Start(Applications app = null, Link link = null)
{
BackgroundWorker RemovalWorker = new BackgroundWorker();
RemovalWorker.DoWork += RemovalWorker_DoWork;
RemovalWorker.RunWorkerCompleted += RemovalWorker_RunWorkerCompleted;
RemovalWorker.WorkerSupportsCancellation = true;
RemovalWorker.RunWorkerAsync(arg);
}
private void RemovalWorker_DoWork(object sender, DoWorkEventArgs e)
{
var app = e.Argument.GetType();
if(app.Name == "Applications")
{
Applications RemovalAppliction = (Applications)e.Argument;
RemovalAppliction.RemoveApplication();
Dispatcher.Invoke(new Action(() =>
{
user.RemoveFromMyApps(user._MyApps[listBox_apps.SelectedIndex]);
}));
e.Result = "apps";
}
else
{
Link RemovalLink = (Link)e.Argument;
RemovalLink.RemoveLink();
Dispatcher.Invoke(new Action(() =>
{
user.RemoveFromMyLinks(user._MyLinks[listBox_links.SelectedIndex]);
}));
e.Result = "links";
}
}
I am trying to pass an optional parameter to my RemovalWorker. However, I receive the following errors:
Inconsistent Accessibility: parameter type 'Applications' is less accessible than method 'MainWindow.RemovalWorker_Start(Applications,Link)'
Inconsistent Accessibility: parameter type 'Link' is less accessible than method 'MainWindow.RemovalWorker_Start(Applications,Link)'
Why is this happening? Am I declaring my optional parameters incorrectly? How should I go about fixing this? The "Removal Worker" is instantiated via button click (hitting delete on a listbox item). The argument I would like to pass is whether it is an "Applications" object or a "Link" object.
The function is not 100% complete - I still need to declare what my argument will be, however, I currently can not compile.
Thanks All!
I guess your Applications and Link is your own class which is not a public class
So when you make public void RemovalWorker_Start the public in this line conflict with nonpublic of Applications and Link
So I'm basically trying to create a search button.
This search is using REGEX.
I think I have it correct but it's not working, Can someone tell me how / where i've gone wrong, Not coded in AGES...
public void SearchFunction(string searchtext)
{
SupporterId();
ReferenceNumber();
ConsignmentNumber();
}
private static void SupporterId()
{
const string sId= "";
var supporterId = Regex.IsMatch(sId, #"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber()
{
const string refNumber = "";
var referenceNumber = Regex.IsMatch(refNumber, #"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber()
{
const string conNumber = "";
var consignmentNumber = Regex.IsMatch(conNumber, #"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
}
}
Those are my Regex, And this is my code behind..
protected void CheckStateClick(object sender, EventArgs e)
{
ConsignmentSearch();
}
private void ConsignmentSearch()
{
var searchclass = new RegexMethods();
searchclass.SearchFunction(txtReferenceNumber.Text);
}
Can anyone tell me where I have gone wrong and HOW I can fix it, Please don't tell me oh your missing this an then don't tell me how to fix it.
IF you can tell me how / what needs adding to be fixed example: add this line of code here .... < >
Please and thank you.
__
THIS IS THE ERROR
Test 'M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
I may be wrong, but it looks like you are only checking empty strings...
How about checking your searchtext like this:
public void SearchFunction(string searchtext)
{
SupporterId(searchtext);
ReferenceNumber(searchtext);
ConsignmentNumber(searchtext);
}
private static void SupporterId(string sId)
{
var supporterId = Regex.IsMatch(sId, #"^[A-F,S,R][0-9]{3,6}$", RegexOptions.IgnoreCase);
}
private static void ReferenceNumber(string refNumber)
{
var referenceNumber = Regex.IsMatch(refNumber, #"^[ABN158][0-9]{6,17}$", RegexOptions.IgnoreCase);
}
private static void ConsignmentNumber(string conNumber)
{
var consignmentNumber = Regex.IsMatch(conNumber, #"&[0-9]{14}$", RegexOptions.IgnoreCase);
}
However, if I understand your code correctly, your searchtext variable only contains the txtReferenceNumber.Text text, so you should only run the ReferenceNumber(string searchtext) method on it.
You provided error text:
__ THIS IS THE ERROR Test'
M:DeliveryInputSystem.Default.AddBox_Click(System.Object,System.EventArgs)' failed:
Object reference not set to an instance of an object.
System.NullReferenceException:
Object reference not set to an instance of an object.
Default.aspx.cs(113,0): at DeliveryInputSystem.Default.AddBox_Click(Object sender, EventArgs e)
There is written cause of error: NullReferenceException and where does it occur Default.aspx.cs(113,0). You need to analyze what is there, in line 113 in Default.aspx.cs and why may it cause NullReferenceException.
If you don't know where to start, start with documentation. According to MSDN documentation for NullReferenceException class:
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null.
You have often also an example there:
1: List<String> names;
2: if (sth) names = new List<String>();
3: names.Add("Major Major Major")
If sth is false then no instance is assigned to names and exception will be thrown.
I have an error in my code and could not figure out how to fix it.
Can you guys help me?
This is the code:
private void typelistbox_SelectedIndexChanged(object sender, EventArgs e)
{
Controller controller = GetCurrentController();
if (controller == null)
{
// TODO velden leegmaken
}
else
{
Controller item = new Controller();
textBox1.Text = controller.Lastfile;
_comPortComboBox.SelectedItem = controller.Port;
Baudratebox.Items.Add(item.Baudrate);
}
}
And this is the error
Error 1 'Flashloader.Controller' does not contain a constructor that
takes 0 arguments
I think you have no standard constructor defined or defined only a constructor that accepts parameters of any kind.