|
Ok, thanks alot ill give it a shot
edit: the word 'famlies' "foreach(FontFamily family in families)"
is underlined in red: word does not exist in current context.
Sorry again, ive added the using system statement etc, wont go away.
edit: before i start to annoy you maybe i presented this out wrong. I created a project just to try this out and see if i can get it working. Thats why i still have all the names like form1 :P
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;
using System.Drawing.Text;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach (FontFamily family in families)
{
if (family.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(family, 12, FontStyle.Regular);
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
modified on Tuesday, May 19, 2009 11:53 AM
|
|
|
|
|
the error is that 'families' does not exist. change it to 'fonts'. Its a mistake in the code
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Even with that error fixed the code you have posted wont do what you want.
so here are the fixes, the should work...
1. in you load event change the 'families' to 'fonts'
2. just before you foreach loop add the following line...
comboBox1.Items.Clear();
3. inside your foreach loop replace all code with this line only...
comboBox1.Items.Add(family.Name);
this should then populate you combo box with all the fonts
4. in your selected index changed event add the following code to alter you textbox font...
textbox1.Font = new Font(comboBox1.Text, 10);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I get a error:
foreach statement cannot operate on variables of type 'System.Drawing.Text.InstalledFontCollection' because <'System.Drawing.Text.InstalledFontCollection' does not contain a public definition for 'GetEnumerator' ...................................
Thats after foreach (FontFamily family in fonts) - changing it from 'family' to 'fonts'
This is so much harder than small basic but i like challenges, ones that not go so well
|
|
|
|
|
Change the foreach from fonts to fonts.Families
|
|
|
|
|
Whoops. I took the code from one of my snippets, so had to adapt it for some reason. Don't worry though, I'm not annoyed in the slightest. You're trying to learn, and that's always a good thing
|
|
|
|
|
Have you tried FontDialog? I dont know if its useful for u:
using System.Windows.Forms;
FontDialog fontDialog = new FontDialog();
if ( fontDialog.ShowDialog() != DialogResult.Cancel )
{
textBox.Font = fontDialog.Font;
}
|
|
|
|
|
Thanks for the imput, ive tried that one
Just wanting the one for combo box i believe it's all me getting confused easy
|
|
|
|
|
Hi,
I have built a class called MyGlobal with a name space of nsMyGlobal. I have added the .DLL to the references and I can see MyGlobal in the list.
I then add a "using MyGlobal;" to the top of my new project C# source and then added a:
myglobal = new MyGlobal( ); // define a reference to it
When I try to build, I'm getting the following error message:
Error 1 The type or namespace name 'MyGlobal' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure what I did wrong...
Thank you,
Glenn
Glenn
|
|
|
|
|
gmhanna wrote: I have built a class called MyGlobal with a name space of nsMyGlobal
gmhanna wrote: I then add a "using MyGlobal;"
See the error now?
No? Try
using nsMyGlobal;
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Damn, Silver again!
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I have days like that, too. Thursdays, mostly...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Works perfect now thanks!!
Glenn
|
|
|
|
|
You say your namespace is 'nsMyGlobal', so is it not...
nsMyGlobal.MyGlobal myglobal = new nsMyGlobal.MyGlobal();
Of course, with that you dont need the 'using' statement, which should be 'using nsMyGlobal;' anyway
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
I'm looking for a way to get a hex string into an integer without converting it. IE: The user enters 10, if I use "uint32 x = Convert.UInt32(String)" I end up with 0x0A, not 0x10. I know if I use a pointer and do it by byte at a time it will work, but I was looking for something a little more straight forward.
Thanks,
Glenn
Glenn
|
|
|
|
|
Hi,
uint.Parse(string, NumberStyles.HexNumber) translates "10" into sixteen.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I'll settle for silver then
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
how about...
int x = int.Parse("10", System.Globalization.NumberStyles.HexNumber);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thank you kindly, that also works.
Glenn
|
|
|
|
|
you appear to be talking to yourself
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You may be a tad slow, however your hearing is OK.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Dare I say... 'Pardon?'
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Half cooked? What's going on?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
williamnw wrote: Half cooked?
Very Good
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job.
<pre>using System.Timers;
public class usersession
{
private static bool sessionalive;
private static Timer usertimer;
public static bool SessionAlive
{
get { return sessionalive; }
set { sessionalive = value; }
}
public static void BeginTimer()
{
try
{
SessionAlive = true;
//usertimer.Start();
usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString()));
usertimer.Enabled = true;
usertimer.AutoReset = false;
usertimer.Elapsed += new ElapsedEventHandler(DisposeSession);
}
catch (Exception ex)
{
return;
}
}
private static void DisposeSession(object source, ElapsedEventArgs e)
{
try
{
SessionAlive = false;
}
catch (System.Exception ex)
{
return;
}
}
public static void ResetTimer()
{
try
{
SessionAlive = true;
usertimer.Stop();
usertimer.Start();
}
catch (Exception ex)
{
return;
}
}
}
</pre>
as you can see begintimer function set the property SessioAlive to true and then instantiate the timer.when that time arrives the disposesession fires and set the property to false.on my main form the constructor calls the begintimer function through startsession function <code>public frMain()
{
InitializeComponent();
StartSession();
//SessionChecker();
}
public void StartSession()
{
try
{
usersession.BeginTimer();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
</code>
so any time the user click on something, i check the usersession.SessioAlive property like so inside this switch case snippet
<code>case "transfer":
if (!usersession.SessionAlive)
{
new LoginForm().ShowDialog();
}
MessageBox.Show("cash back transfert page");
break;
</code>
and inside the loginForm if login is correct we call the usersession.ResetTimer() and resettimer set SessionAlive property to true then the user can work again until there is no activity until session expores again.
<code>
this.DialogResult = DialogResult.OK;
usersession.ResetTimer();
this.Close();
</code>
It's working just fine.Now i really wanted the checking to be run in background(the commented sessionchecker on the main form) that's were i need your advice.here i use forms.timer on the main form to create a small job but since forms.timer doesn't have autoreset it doing an endless loop by calling the loginform and i have to stop the process from the task manager.
<pre>
private void SessionChecker()
{
try
{
check = new Timer();
check.Enabled = true;
check.Interval = 1000;
check.Tick += new EventHandler(check_Tick);
}
catch (Exception)
{
throw;
}
}
void check_Tick(object sender, EventArgs e)
{
try
{
if (!usersession.SessionAlive)
{
new LoginForm().ShowDialog();
check.Stop();
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
</pre>
How to make the cheking being run in the background and when session expires block the application by asking credentials?I can't really see the mistake i'm doing.But since it's not working as expected i'm doing something wrong.Can you help me solve this?Thanks for reading
eager to learn
|
|
|
|