Visual Studio Setting label text from another class C# - visual-studio

I have read some answers and some tutorials but they either didn't work or were too complex for me to understand.
I am trying to get a different class to change A labels text but It did not work. Here is my code:
public static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Mainprog mp = new Mainprog();
Mainprog.count += 25;
mp.Counter.Text = Convert.ToString(Mainprog.count);
}

Related

I can't use a Winforms Control created with a Class

I was looking for a Circular Picture Box for my app and I stumbled across this code (IT IS NOT MINE) and I've tried as many times as I could but I can't find any mistake. I have followed every step that was made in the tutorial for this Rounded Picture Box so it can't be a miscopy because it was working perfectly in the tutorial.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace New_Radio_Barcelona.Controls
{
class RashiCircularPictureBox : PictureBox
{
private int border = 2;
private Color colorBorder = Color.RoyalBlue;
private Color colorBorder2 = Color.HotPink;
private DashStyle borderstyle = DashStyle.Solid;
private DashCap borderCap = DashCap.Flat;
private float gradiant = 50f;
public RashiCircularPictureBox()
{
this.Size = new Size(95, 95);
this.SizeMode = PictureBoxSizeMode.StretchImage;
}
public int Border
{
get
{
return border;
}
set
{
border = value;
this.Invalidate();
}
}
public Color ColorBorder
{
get
{
return colorBorder;
}
set
{
colorBorder = value;
this.Invalidate();
}
}
public Color ColorBorder2
{
get
{
return colorBorder2;
}
set
{
colorBorder2 = value;
this.Invalidate();
}
}
public DashStyle Borderstyle
{
get
{
return borderstyle;
}
set
{
borderstyle = value;
this.Invalidate();
}
}
public DashCap BorderCap
{
get
{
return borderCap;
}
set
{
borderCap = value;
this.Invalidate();
}
}
public float Gradiant
{
get
{
return gradiant;
}
set
{
gradiant = value;
this.Invalidate();
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Size = new Size(this.Width, this.Width);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
var graphic = pe.Graphics;
var rect = Rectangle.Inflate(this.ClientRectangle, -1, -1);
var rectborder = Rectangle.Inflate(rect, -border, -border);
var size = border > 0 ? border * 3 : 1;
using (var bordercolorG = new LinearGradientBrush(rectborder, colorBorder, colorBorder2, gradiant))
using (var path = new GraphicsPath())
using (var pen = new Pen(this.Parent.BackColor, border))
using (var penborder = new Pen(bordercolorG, size))
{
graphic.SmoothingMode = SmoothingMode.AntiAlias;
penborder.DashStyle = borderstyle;
penborder.DashCap = borderCap;
path.AddEllipse(rect);
this.Region = new Region(path);
graphic.DrawEllipse(pen, rect);
if (border > 0)
{
graphic.DrawEllipse(penborder, rectborder);
}
}
}
}
}
I compile the project and then try to add it to the Design tab as shown in the tutorial. It says it could not be loaded. I was trying to understand what is not working properly but I still do not find the mistake. Some help plis?
Another aspect to take into consideration is the fact that in class RashiCircularPictureBox : PictureBox puts 1 reference above the code and in public RashiCircularPictureBox() it says 0 references. It may be for this but I'm no expert on Classes and I'm stuck in this stupidity. if anyone could clear my mind about this issue I would be so grateful about it
The designer in most versions of Visual Studio up until recently has been a 32-bit process. So if the control was built as 64-bit, it wouldn’t be able to load it at design-time, but VS would still be able to create 64-bit applications that can use the 64-bit control at runtime.
This means if you build your control as 32-bit or AnyCPU, it should solve the design-time loading problem.
The release notes of Visual Studio 2022 version 17.0.0 state that “devenv.exe is now 64-bit only”. I haven’t tried this myself, but it probably means you can now use 64-bit controls at design time with the newer versions of VS.
In all cases, AnyCPU should work.

Awesomium WebControl not showing

Sorry if this sounds a little noobish, but I just installed Awesomium SDK, added references to the project, and I can't find the "WebControl" in the ToolBox. What am I doing wrong?
All you have to do is run the setup to uninstall and reinstall it in the assembly folder.
http://wiki.awesomium.net/getting-started/setting-up-on-windows.html
This may help, go to your project properties and check the target framework.It should be .Net Framework 4 client profile or above
You should create WebView, add it to form, set it location and size and set source URI!
try to include namespaces:
using Awesomium;
using Awesomium.Windows.Forms;
using Awesomium.Core;
static class Program {
static Form1 f1 = new Form1();
static Form fm = new Form {};
static WebBrowser wb = new WebBrowser { Dock = DockStyle.Fill};
//private static WebView wv;
static WebControl wc = new WebControl{Visible = true};
//static WebView wv;// = new WebView(fm.Handle);
[STAThread]
static void Main(string[] args) {
//f1.ShowDialog(); return;
wc.ViewType = WebViewType.Window;
wc.Location = new System.Drawing.Point(0,0);
wc.Size = new System.Drawing.Size(1000,1000);
fm.Controls.Add(wc);
//wv = new WebView(fm.Handle);
//fm.Controls.Add(wv.con);
wc.Source = new Uri("https://stackoverflow.com");
Task k = new Task(delegate {
Thread.Sleep(200);
try {
fm.Invoke(new MethodInvoker(delegate {
try {
MessageBox.Show(wc.Source.ToString());
} catch {
MessageBox.Show("2");
}
}));
} catch {
MessageBox.Show("1");
}
});
k.Start();
fm.ShowDialog();
}//main

How can i run a Unity Game inside Visual Studio (2013)

I need to be able to run a Unity game inside a Visual Studio form for my school project.
I'm not that good yet with VS and this kind of stuff is still complicated for me and I don't even know if it is possible.
This is what I have:
And this is the result that I need:
Is this even possible? If so, how or point me in the right direction please.
EDIT:
Found how to do it:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private void button1_Click(object sender, EventArgs e)
{
var clientApplication = Process.Start("C:/Users/ricardo.coelho/Desktop/Unity_VS_Test.exe");
Thread.Sleep(500);
SetParent(clientApplication.MainWindowHandle, panel1.Handle);
}
Yes you can do that, via the command line parameters.
The parameter you are looking for is -parentHWND, as stated in the documentation. The documentation also contains an example that could help you out.
From there (in a C# application) it is a matter of
process = new Process();
process.StartInfo.FileName = "Child.exe";
process.StartInfo.Arguments = "-parentHWND " + panel1.Handle.ToInt32() + " " + Environment.CommandLine;
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForInputIdle();
EnumChildWindows(panel1.Handle, WindowEnum, IntPtr.Zero);

Deployment of application with sound effects and txt document included

I have made an simple application which uses few sound effects and .txt document for storing some info(those files are stored into my projects bin/Debug directory).The app works fine on my PC, but when I run the .exe file on other computer, it works until the sound or .txt file is necessary(then is gives me a warning message telling that sound or .txt file isn't reachable).
How can I solve this problem, i mean, what should I do to make my app work properly on other PC's as well.Thanks!
Edit:
Here it the code which uses only sound effects(i'm changing them, so there are more than one sound)
{
public partial class GameScreen : Form
{
bool sound;
string sound1;
string sound2;
string sound3;
SoundPlayer sp1;
public GameScreen(string PlayerName)
{
InitializeComponent();
sound1 = "Air_Horn.wav";
sound2 = "TaDam.wav";
sound3 = "Bonus.wav";
sp1 = new SoundPlayer(sound1);
sound = true;
}
private void GameScreen_Load(object sender, EventArgs e)
{
if (sound == true)sp1.Play();
}
}
}
and here is the code using sound effects and .txt document:
{
public partial class VictoryForm : Form
{
SoundPlayer sp2;
string results;
bool sound_eff;
public VictoryForm(string statistics, bool _sound)
{
InitializeComponent();
sp2 = new SoundPlayer("Cheering3.wav");
results = statistics;
sound_eff = _sound;
}
private void VictoryForm_Load(object sender, EventArgs e)
{
if (sound_eff == true) sp2.Play();
}
private void VictoryForm_FormClosing(object sender, FormClosingEventArgs e)
{
StreamWriter sw = new StreamWriter("Results.txt", true);
sw.WriteLine(results);
sw.Close();
}
}
}
Sounds like you a) have not copied your texts or sound to the other computer or b) use wrong path to them. To be sure, print out the full path to the text or sound files and check if the intended files are really there. I bet they are not. ...
Btw, the contructor of StreamWriter says about its arguments: path = "The complete file path to write to", but your "Result.txt" is not a full path.

VS 2010 Beta1 "Historical Data Has not been Collected"

I am trying out the Historical Debugger in VS2010 Beta 1.
I have it turned on in the settings (at least I think I do), but when I try to examine objects the value is:
[Historical Data Has Not Been Collected]
Any Ideas how to get this to show the actual value?
Here is the code in question:
public partial class Form1 : Form
{
public Form1()
{InitializeComponent();}
private void button1_Click(object sender, EventArgs e)
{
int numer = Int32.Parse(txtNumerator.Text) ;
int denom = Int32.Parse(txtDemoninator.Text);
float answer = DivideValues(numer, denom);
txtAnswer.Text = answer.ToString();
}
private static float DivideValues(int numer, int denom)
{
float answer = numer / denom;
return answer;
}
}
To get it to work right you need to use the tree view in the Debug History Window. The navigation arrows in the gutter seem to be more of a distraction than a help as it lets you get to areas that are not recorded.
Also, local variables are not recorded. This is by design.

Resources