How to add ui frameworks to a c# form - c#

overflow, im having trouble trying to add a ui framework , for exmple metro framework, to my c# form.
I know that i have to include the reference and include it with
using MetroFramework.Forms;
but im not sure what else to do here and when ever i try and google it, i just get websites that try and sell me a framework package.
Here is my code:
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 MetroFramework.Forms;
namespace FrameworkTest
{
public partial class Form1
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
I know this may be a silly question but any help would be much appreciated.

Thanks to Crowcoder I found out that I was supposed to add
MetroForm after Form1 like:
public partial class Form1 : MetroForm {
//Code goes here
}

Related

Creating partial class for wpf functions and events

I've a WPF program which it's MainWindows.xaml.cs has many functions and events. I want to make it more readable so I moved some of the functions and events in a separate class named "partialClassMainWindow.cs". I moved all button events to it. now when I click on a button it must go to button_Click function in partialClassMainWindow but a new funciton is created in MainWindows.xaml.cs.
how can I prevent it?
for example consider this simple program:
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//moved to partialClassMainWindow:
//private void button1_Click(object sender, RoutedEventArgs e)
//{
//}
}
}
partialClassMainWindow.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace WpfApplication3
{
public partial class MainWindow:Window
{
public void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Hello World";
}
}
}
Don't think that you can avoid it. It looks like Visual studio just checks the code behind file and not any other files with more partial code. But the other guys are right MVVM is the way to go and normally you have little or none code behind. Only typical view stuff you would handle there, all the business logic goes into the viewmodel.
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Is a good place to start reading about MVVM.

Unable to load dll when inheriting from a form

I'm trying to create a new form (child form) that inherits from another form (parent form), and the problem is that, when I try to view the child form design view (in order to modify some controls), Visual Studio throws the following error: "Unable to load DLL 'fmodex': the specified module could not be found inherited form. (Exception from HRESULT: 0x8007007E)". The strange thing is that it actually works fine when I run the program, the error is only shown when I try to enter to the design view of the child form. I've checked the dll path and it's correct. Here's part of the the parent's code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
protected EventList eventList;
protected FMOD.System system;
protected int count;
public Form1()
{
InitializeComponent();
//Create a FMOD System object and initialize.
FMOD.RESULT result;
result = FMOD.Factory.System_Create(ref system);
result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
//Event list
eventList = new EventList(0,system);
count = 0;
}
}
}
And the child's code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : WindowsFormsApplication1.Form1
{
public Form2()
{
InitializeComponent();
}
}
}
Does anybody knows what could be happening? I can't understand why I can see the design view of the parent form and not the child form one.
Thanks in advance.

Unable to programmatically set form background image from picture resource

I just want to set the background image of another form to a png file picture resource I added
I have the following in my MAstrategyBldrForm.cs file:
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 MAStrategyBuilder
{
public partial class MAstrategyBldrForm : Form
{
private CrossPicsForm crossPic;
public MAstrategyBldrForm()
{
InitializeComponent();
crossPic = new CrossPicsForm();
}
....
....
.... later in same file:
private void MAcrossPicButton_Click(object sender, EventArgs e)
{
crossPic.BackgroundImage = (Bitmap) (Properties.Resources.ResourceManager.GetObject("Moving Avgs Cross.png"));
crossPic.Show();
}
....
....
In my CrossPicsForm.cs file I 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 MAStrategyBuilder
{
public partial class CrossPicsForm : Form
{
public CrossPicsForm()
{
InitializeComponent();
}
}
}
Everything compiles but when I click my button control in the mastrategy... form, a CrossPicsForm window is displayed that is blank. Darn!
You won't get an exception when you mis-spell the resource name, ResourceManager simply returns null and that leaves the BackgroundImage property unchanged. You did, it would normally be named "Moving_Avgs_Cross" without the .png extension.
Do favor using the property that was added by the resource designer instead. That ought to resemble:
crossPic.BackgroundImage = Properties.Resources.Moving_Avgs_Cross;
Use IntelliSense to help you fall in the pit of success here.

bringing two projects together

I have a simple window application I am starting and I was given another file I would like to bring into the new project. How do I bring them both together to work as one file?
New Project
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Other
using System;
using System.Text;
using System.IO;
using System.Net;
namespace CaptchaClient
{
public static class SampleUse
{
public static void SampleSolve()
{
}
}
public class CaptchaSolver
{
}
public enum ResponseState
{
}
}
This screenshots shows the how yo do he procedure
Right click on your project in the Solution Explorer and click Add Existing Item. Then browse to the other class file. Once imported, you might want to change its namespace to the one you are using in your project.

Session Objects in Global.asax File

I am working on a Web Application and i want that when the user logged In the UserID should be stored in Session. I know how to create Session.
Session["UserID"] = myvalue;
But i want that to be used on everypage. so i dont want to write code or check for session availability on every page. will Global.asax file help me ?
If i write session in Session_Start() then will that be accessible on all pages ? and if expired the return to login page.
Just require proper guidance. Thanks
I used to write as a separate class to handle session and return it as a property. I can write all the condition in the class.
I highly suggest creating a basepage that is inherited by every page but the login. this way you are only creating the session variable code on one page but that code is accessible by any page that inherits it.
edit with small example:
when your user is authenticated you need to set your session variable
currently your pages probably look something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
what you need to do is create a separate class file, basepage.cs for example that looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public class basepage : System.Web.UI.Page
{
protected int GetItem()
{
return Convert.ToInt32(Session["myvalue"]);
}
}
}
and then your original page would look more like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : basepage
{
protected void Page_Load(object sender, EventArgs e)
{
int whatINeed = GetItem();
}
}
}
as you see instead of your page inheriting the System.Web.UI.Page it is inheriting the basepage (which in turn inherits System.Web.UI.Page).

Categories

Resources