I am trying to make a program so if my Skype name/id is David it wont do anything but if its someone else Skype name/id it will change the RichMoodText I know how to change the RichMoodText but its just detecting if its a certain profile
Please Help
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 SKYPE4COMLib;
namespace Skype_Tools_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//RMT Means RichMoodText
string RMT = "Hi";
//CFN Means Creators FullName
string CFN = "David Fedrick";
Skype skype = new Skype();
skype.Attach();
//skype.CurrentUserProfile.RichMoodText = RMT;
if skype.CurrentUserProfile.FullName = CFN; <----
Cannot implicitly convert type 'string' to 'bool'
}
}
}
= is an assignment operator. You should use comparison operators in if statements, in this case ==. Also the statement should be in parenthesis, like
if (a == b)
{
\\ do your thing
}
Related
Hello it is probably easy question for you, I'm a beginner and I'm making my own simple game and I want to use a Class:Gamer, which I want to initialize in MainWindow(Form1.cs) from a save file. From then, I want to use it on another Forms aswell, but somehow I can't make the instance go public.
Could you tell me what I'm doing wrong? Or is there another way how to solve this?
Thank you :)
Code on Form1:
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.Drawing.Text;
using System.IO;
namespace THE_GAME
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Gamer Player;
private void MainWindow_Load(object sender, EventArgs e)
{
//load from savefile lvl;hp;money;gun;armor,name
string allData = File.ReadAllText("../../saveFile/save.txt");
string[] dataFromSave = new string[5];
dataFromSave = allData.Split(';');
Player = new Gamer(dataFromSave[0], dataFromSave[1], dataFromSave[2], dataFromSave[3], dataFromSave[4], dataFromSave[5]);
}
}
}
Code on secondForm2:
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.Drawing.Text;
namespace THE_GAME
{
public partial class Statistics : Form1
{
public Statistics()
{
InitializeComponent();
}
private void Statistics_Load(object sender, EventArgs e)
{
//labels stats
labelName.Text = Form1.Player.GetName();
labelHealth.Text = Form1.Player.GetHealth().ToString();
labelMoney.Text = Form1.Player.GetMoney().ToString();
}
private void buttonBack_Click(object sender, EventArgs e)
{
MainMenu menu = new MainMenu();
menu.Show();
this.Close();
}
}
}
Thank you for your time.
To get at the Gamers Player object from a different Form just do
Form1.Player;
ie
var nam = Form1.Player.Name;
Form1.Player.Die();
etc
PS As I said in a comment - its extremely odd to dereive a form of yours from another one of your forms. Like this
public partial class Statistics : Form1
Hello I am working on c# simple project.
This is the code:
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.Threading;
using Microsoft.Win32;
using System.IO;
private void SetStartup()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (chkStartUp.Checked)
rk.SetValue(AppName, Application.ExecutablePath);
else
rk.DeleteValue(AppName,false);
}
namespace web1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// open browser
Thread.Sleep(6000);
System.Diagnostics.Process.Start("https://google.com/");
}
}
}
It shows errors "The name "AppName" does not exist in the current context" and "The namespace cannot contain members such as fields or methods directly"
I want to:
If I click on this program .exe, it should run on the startup (every startup).
How to deal with it? I've tried so many ideas, but doesn't helped.
Thanks in advance.
BTW: it's my first time here, nice to meet you all!
This question already has answers here:
Why does Property Set throw StackOverflow exception?
(3 answers)
Closed 2 years ago.
I'm using C# to develop a windows forms application and I required to store certain values (Ex: UserID and Role), in order to use them again in various forms throughout the application.
The User ID and the Role will be changed with each login.
So tried using static classes.
To test it out first, I did the following.
Created "Form1" with a textbox and a button.
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 btnDisplay_Click(object sender, EventArgs e)
{
common.text = textBox1.Text;
Form2 obj = new Form2();
obj.Show();
}
}
}
Then created "Form 2" with only a label.
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 Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = common.text;
}
}
}
And to interconnect these two forms, created the following class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication3
{
public static class common
{
public static string text
{
get
{
return text;
}
set
{
text = value;
}
}
}
}
The purpose was to see if the label text on form2 would change when clicked on the button after entering text into the textbox in form1.
When running the code, the following error was thrown. Displays that this is thrown from the "set" method of the class.
An unhandled exception of type 'System.StackOverflowException' occurred in WindowsFormsApplication3.exe
If anyone could provide any clarity on this, it would be highly appreciated.
Thanks in advance.
Your set method is calling itself.
You need to add private string and change it and then return the changes via get.
Try this:
private static string _text;
public static string text
{
get
{
return _text;
}
set
{
_text = value;
}
}
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.Net;
namespace Garfield
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
download("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1", "e.gif");
}
public void download(string link, string name)
{
using (WebClient Client = new WebClient())
{
Client.DownloadFile(link, name);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
Using the code above I downloaded an image online, now how do I set the location of that file to somewhere else instead of it being in the debug folder?
This can be done through mentioning a valid desired location and name when download.
Client.DownloadFile("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1",
#"C:\yourfolder\yourfilename.png");
You can pass an entire path to your download method:
download("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1", "C:\\Users\\(You)\\Documents\\e.gif");
Just replace everything before "e.gif" with the path you desire.
See more here: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netframework-4.8
Here's the relevant code:
ClickMeGame.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary
{
public class ClickMeGame
{
public OnClickMe onClickMeCallback;
public int score;
public ClickMeGame()
{
score = 0;
}
private void IncrementScore()
{
score++;
}
}
}
ClickMeCallBackDefinitions.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary
{
public delegate void OnClickMe();
}
MainWindow.cs (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;
using ClassLibrary;
namespace ClickMe
{
public partial class mainWindow : Form
{
private ClickMeGame game;
public mainWindow()
{
InitializeComponent();
game = new ClickMeGame();
game.onClickMeCallback = clickMeButton_Click();
}
private void clickMeButton_Click(object sender, EventArgs e)
{
UpdateUI();
}
private void UpdateUI()
{
scoreLabel.Text = string.Format("The score is: {0}", game.score);
}
}
}
So what I'm trying to do is, when the user clicks a button present on the form, I want a label on the form to update with the game score which increments with every click.
I'm learning about/want to be able to do this with delegates in that I want to separate the project into 2 tiers; Presenation and Logic. I know it's unnecessary to do so, but I'd like to make it such that when you click the button, the Windows Form receives information about the game score via delegates/callback methods. I'm unsure how to do this, but I tried making the callback definition and referencing it, but I'm lost from there.
Assuming that the UI button uses the click event clickMeButton_Click then here you go.
public partial class mainWindow : Form
{
private ClickMeGame game;
public mainWindow()
{
InitializeComponent();
game = new ClickMeGame();
game.onClickMeCallback = param => UpdateUI();
}
private void clickMeButton_Click(object sender, EventArgs e)
{
game.onClickMeCallback.Invoke();
}
private void UpdateUI()
{
scoreLabel.Text = string.Format("The score is: {0}", game.score);
}
}