Im creating a skype tool and it is goin great but my skype resolver key http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo= expired. Is there any way i can make one with C# and put it in the program in replace of the code below?! Thanks (:
private void metroButton27_Click_2(object sender, EventArgs e)
{
WebRequest.Create("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
this.metroTextBox16.Enabled = true;
if (string.IsNullOrEmpty(this.metroTextBox15.Text))
{
MessageBox.Show("Enter A Skype Username", "Box Not Filled In");
this.metroTextBox16.Enabled = false;
}
else
{
this.metroTextBox16.Text = new WebClient().DownloadString("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
}
}
I made a skype resolver in Java, and i'm recording it with a better GUI in C#.
Try this API: http://data-stresstest.nl/boot/api.php?skype=(skypename here)
Don't really know what you are asking for.
Try this??
private void metroButton27_Click_2(object sender, EventArgs e)
{
if (metroTextBox16.Text == "") //Checks if Textbox = Blank.
{
MessageBox.Show("Enter a username.", "ERROR"); //Shows a message box.
}
else
{
this.metroTextBox16.Text = new WebClient().DownloadString("http://resolveme.org/api.php?key=51e77c68b11df&skypePseudo=" + this.metroTextBox15.Text);
}
}
Related
I'm new about C#, I learnt C programmation for one year now.
I created a Window Form which asks the user to complete a registration form.
My registration form
I'd like to display an error message below the buttons when a field is not filled or a field isn't well used.
I used this basic code :
private void button1_Click(object sender, EventArgs e)
{
if (!isOkay(userTextBox.Text))
{
label5.Text = "Please, enter an username.";
label5.Visible = true;
}
else if (!isOkay(mailTextBox.Text))
{
label5.Text = "Please, enter a mail address.";
label5.Visible = true;
}
else if (!confirmMailTextBox.Text.Equals(mailTextBox.Text) || !isOkay(confirmMailTextBox.Text))
{
label5.Text = "Please, match both mails addresses.";
label5.Visible = true;
}
else if (!isOkay(passwordTextBox.Text))
{
label5.Text = "Please, enter a password.";
label5.Visible = true;
}
else
{
label5.Text = "Valid form, yay !";
label5.Visible = true;
}
}
private Boolean isOkay(string textBoxContent)
{
return (textBoxContent.Length > 0 || textBoxContent.Equals(null));
}
Are there any elegant or optimized ways to do it properly ? I found some Error providers, but apparently error providers open a pop-up, and I just want a "red error message below buttons".
Can you give me some help ? :)
Given a class like this
public class RequiredFieldsError
{
private List<string> errors;
public RequiredFieldsError()
{
errors = new List<string>();
}
public int Count
{
get{return errors.Count;}
}
public void AddField(string errorField)
{
errors.Add(errorField);
}
public override string ToString()
{
if(errors.Count == 0)
return string.Empty;
else
{
string fields = string.Join(Environment.NewLine, errors);
fields = "The following fields contains errors:" + Environment.NewLine + fields;
return fields;
}
}
}
then you could change your code to
private void button1_Click(object sender, EventArgs e)
{
RequiredFieldsError rfe = new RequiredFieldsError();
if (!isOkay(userTextBox.Text))
rfe.AddField("User name missing, Please, enter an username.";
if (!isOkay(mailTextBox.Text))
rfe.AddField("Email address missing, Please, enter a mail address.";
if (!confirmMailTextBox.Text.Equals(mailTextBox.Text) || !isOkay(confirmMailTextBox.Text))
rfe.AddField("Email address doesn't match the confirmation email");
if (!isOkay(passwordTextBox.Text))
rfe.AddField("Password missing, Please, enter a password.";
if(rfe.Count > 0)
{
// MessageBox.Show(rfe.ToString());
label5.Text = rfe.ToString()
label5.Visible = true;
}
}
This approach avoids the unnerving situation (for your user) when he/she receives an error message, he/she fixes it just to receive another error message at the next attempt to confirm the form.
Of course your label should be tall enough to show all the possible messages or just use a messagebox.
I suggest also to change your IsOkay function to
private Boolean isOkay(string textBoxContent)
{
return !string.IsNullOrWitheSpace(textBoxContent));
}
this will handle also a string composed just of one or more spaces. (not null and not length==0)
You can use ErrorProvider. It show's an error icon after your textbox.
For one of your textboxes for example:
if (!isOkay(userTextBox.Text))
{
errorProvider1.SetError(userTextBox "yourmessage");
}
else{
errorProvider1.Clear();
}
Link: http://www.dotnetperls.com/errorprovider
I'm working on a C# windows application project which requires to display the result of five check boxes in a message.After the user checked all he wants ,I have to display what he checked in a message show box. Here is what I did so far :
private void Display_CheckedChanged(object sender, EventArgs e)
{
if (chkSkis.Checked == true)
{
message = message +chkSkis.Text;
}
if (chkGoogles.Checked == true)
{
message = message +chkGoogles.Text;
}
}
private void displayOrderToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("You chose the following equipments:\n" + message,
"Flyers Sports Club");
}
It is best practice to use StringBuilder. In addition, using the code you posted, if the user un-checks a box, you aren't removing those from the string. I would suggest building the string inside the displayOrderToolStripMenuItem_Click event like so:
private void displayOrderToolStripMenuItem_Click(object sender, EventArgs e)
{
StringBuilder message = new StringBuilder();
if (chkSkis.Checked == true)
{
message.AppendLine(chkSkis.Text);
}
if (chkGoogles.Checked == true)
{
message.AppendLine(chkGoogles.Text);
}
MessageBox.Show("You chose the following equipments:\n" + message.ToString(),
"Flyers Sports Club");
}
Having a lot of trouble with this. I'm working on a large project, so there's only a few classes I'm interested in and working on. Basically, these are forms - one is a main editor where a user edits details and the other is used to assign a pin number. In the main editor form, if the user has a pin, they can choose to edit this pin. Here's where my problem lies - if I edit the pin, what I'm doing in the code is deleting the old pin and adding the new one. However, the database doesn't update until AFTER the editor form is closed. Therefore, I'd like to call the method that does change the database on the OKButton click, if I could. The problem I'm facing is I don't know how.
Here is the DB code, we'll say the class is called DetailsConn:
public string editPin(int driverID)
{
if (SchemaChecker.PINAvailable())
{
string sql = "EditPIN";
using (SqlCommand cmd = new SqlCommand(sql, base.connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Remove("#nDriverID");
cmd.Parameters.AddWithValue("#nDriverID", driverID);
cmd.Parameters.Remove("#nPIN");
SqlParameter pinParameter = cmd.Parameters.Add("#nPIN", SqlDbType.Char);
pinParameter.Direction = ParameterDirection.Output;
pinParameter.Size = 32;
cmd.ExecuteNonQuery();
return pinParameter.Value.ToString();
}
}
return "";
}
Here's the code for my edit:
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.listViewDriverTags.SelectedItems.Count > 0)
{
ListViewItem lvi = this.listViewDriverTags.SelectedItems[0];
DriverTag driverTag = lvi.Tag as DriverTag;
else if (blahTag.blahType == 2)
{
buttonAssignPIN_Click(sender, e);
}
//message stuff and dialog boxes with localization info
if (dr == DialogResult.Yes)
{
this.listViewDriverTags.Items.Remove(lvi);
if (Tag.id != -1)
{
TagsToBeDeleted.Add(driverTag);
}
}
if (dr == DialogResult.No)
{
this.listViewTags.Items.Clear();
this.listViewTags.Items.Add(lvi);
}
}
}
Here's my buttonAssignPIN stuff:
private void buttonAssignPIN_Click(object sender, EventArgs e)
{
using (AssignPINForm form = new AssignPINForm())
{
if (form.ShowDialog(this) == DialogResult.OK)
{
DriverTag PIN = DriverTag.GetNewPIN(form.DriverTag);
ListViewItem lvi = this.listViewTags.Items.Add(PIN.driverTag);
lvi.SubItems.Add(this.TagTypes[PIN.TagType]);
lvi.Tag = PIN;
}
}
}
And finally, here's my AssignPINForm code:
public partial class AssignPINForm : Form
{
public AssignPINForm()
{
InitializeComponent();
this.buttonOK.Click += new EventHandler(buttonOK_Click);
this.buttonCancel.Click += new EventHandler(buttonCancel_Click);
this.buttonOK.Enabled = false;
this.textBoxPin.TextChanged += delegate(object sender, EventArgs e)
{
String pattern = #"^[0-9]{4,20}$";
Regex regex = new Regex(pattern);
buttonOK.Enabled = regex.IsMatch(textBoxPin.Text);
};
LoadStrings();
}
public void LoadStrings()
{
//stome stuff
}
public string DriverTag
{
get { return this.textBoxPin.Text; }
set { this.textBoxPin.Text = value; }
}
private void buttonOK_Click(object sender, EventArgs e)
{
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void AssignPINForm_Load(object sender, EventArgs e)
{
}
}
I know it's kind of all over the place but I've provided everything I think is relevant. The middle two snippets are in the same class too, and the DB stuff is the same solution but a different project. I'd be grateful if someone can decipher what I'm after and help me out, it's the only thing I have left to do on this particular bit!
Thanks!
Not sure I fully got what you're after and I agree with some of the comments that this isn't the best of practice but I guess what you're after is to update the buttonOK_Click method to something like this:
private void buttonOK_Click(object sender, EventArgs e)
{
using(DetailsConn connection = new DetailsConn())
{
int driver = -1;
if(int.TryParse(this.DriverTag, out driver)) {
connection.editPin(driver);
}
}
}
Also, you may want to remove any other possible references to the editPin() function.
I actually figured out that even if I got that working correctly, it wasn't going to solve my problem. I've had to call a new procedure and declare that in the database schema - basically it was a lot more complicated than what I was giving it credit for. Thanks for the responses nonetheless.
How can access to the Location Service API be disabled?
I did receive a letter from the Microsoft Development Center which contains this tip:
Your app must provide in-app settings that allow the user to enable
and disable your app's access to and use of location from the Location
Service API.
Can anyone provide further assistance on how I go about doing this?
Paste this code right after InitializeComponent(); in MainPage.xaml. You will have to add reference to IsolatedStorage by this line using System.IO.IsolatedStorage;.
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
return;
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
Also create a Settings.xaml page with a ToggleSwitch which has the following code:
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
locationSwitch.IsChecked = true;
}
else
{
locationSwitch.IsChecked = false;
}
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
private void locationSwitch_Checked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
private void locationSwitch_Unchecked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
And on the page that you use Location / GPS data include the following code:
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
//Do Something
}
else
{
MessageBox.Show("Please enable location services to use this feature. You can turn it on from Settings.");
}
This will surely help. I use the same. Do upvote and mark as answer if this helps you too :)
Does your app use location services and you need to have the ability to disable it OR are you asking in general?
If it's the first then just stop collecting data and disable it in your app. If it's the second then go into the WPmanifest and uncheck it
I am working on a program to manage a minecraft server with a local UI as well as a remote interface. I have a button on a ribbon bar that will enable or disable the remote interface and a textbox for inputting the port. Currently, I disable the textbox when the networking is enabled, but, disabling does not re-enable the textbox after I set it to true again (and setting a breakpoint reveals it to still be false).
private void NetToggleChecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = false;
if (ButtonPressedByUser) {
var result = MessageBox.Show("Are you sure you want to enable networking with the current settings?" +
" If not properly configured, it may be possible for an attacker to enter your server.",
"Simple Bukkit Wrapper", MessageBoxButton.YesNo, MessageBoxImage.Warning,
MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "true";
int port;
if (!int.TryParse(Config.NetConf["port"], out port)) {
MessageBox.Show("Port could not be parsed (is it a number?)");
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
Net.Listener.StartListening(port);
}
private void NetworkToggleUnchecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = true;
if (ButtonPressedByUser) {
var result =
MessageBox.Show("Are you sure you wish to disable all networking to your server? It will " +
"be impossible to connect to it remotely and any existing connections will be closed.",
"", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = true;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "false";
Net.Listener.StopListening();
}
Thank you for any help resolving why the textbox will not enable again.
Old Question but i kept coming across it while searching for an answer so figured i'd post an answer anyways. There is a bug in the ribbonTextbox control that results in isenabled always being false if there is no command associated. There are 2 ways round this from what i have found:
1: Create a new control based on the ribbontextbox and override the isenabledcore property to always return true. As shown here Cannot set RibbonTextBox isEnable to False
2: Create a dummy command and associate it with the control
public static readonly ICommand DummyCommand = new RoutedCommand("Dummy", typeof(Control));
public static void Dummy(Object sender, ExecutedRoutedEventArgs e)
{
// Do nothing its a dummy command
}
public static void CanDummy(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
as described in a comment in this link http://blogs.msdn.com/b/wpf/archive/2010/10/21/wpf-ribbon-october-2010-update-details.aspx .
AS i said probably no help to the original poster but i kept coming across it while looking for an answer so it may save someone else a few minutes of googling time.