|
This program should show all the installed fonts in their typeface but it doesn't show anything instead whats wrong?
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FontViewer
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage1});
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(624, 353);
this.tabControl1.TabIndex = 2;
//
// tabPage1
//
this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView1});
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(616, 327);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Installed Fonts";
//
// listView1
//
this.listView1.CausesValidation = false;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader2});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Scrollable = ((bool)(configurationAppSettings.GetValue("listView1.Scrollable", typeof(bool))));
this.listView1.Size = new System.Drawing.Size(616, 327);
this.listView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.listView1.TabIndex = 1;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader2
//
this.columnHeader2.Text = "Names";
this.columnHeader2.Width = 595;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "About";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// columnHeader1
//
this.columnHeader1.Width = 612;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(624, 353);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Leons Font Program";
this.Load += new System.EventHandler(this.Form1_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
Graphics grfx = CreateGraphics();
Color c = Color.Black;
Brush brush = new SolidBrush(c);
float y = 0;
FontFamily[] aff = FontFamily.Families;
foreach (FontFamily ff in aff)
{
if(ff.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(ff, 12);
grfx.DrawString(ff.Name, font, brush, 0, y);
y += font.GetHeight(grfx);
}
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Made By Leon Radley, 2002");
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
Cheers
|
|
|
|
|
I *think* your problem is that you are doing the drawing on the load event which actually occurs before the form is displayed.
Try taking the stuff in the draw event and putting it in the paint event instead and see if that works.
|
|
|
|
|
I understand how to access functions from a DLL that is not a COM DLL. However, I would like to know how I can access the classes from a NON-COM DLL.
A tutorial, or sample code would be great, or at worse a tool that created a .NET wrapper for you.
Thanks
Coding is a way of life. It's in the air we breath. It pumps through our veines. Without it we soon crumble to dust. - Rodney S. Foley
|
|
|
|
|
You need to use DllImport. Here is an example straight from MSDN :-
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
First I like to say I appreciate your attempt to help, however, please read a post and understand it before you reply.
Okay I will try to state this again. As I said, I understand how to access functions from a DLL. Which is what you just provided an example for.
What I asked for in the post, and what is also stated in the subject is how to access CLASSES from a NON-COM DLL. That would be a DLL that is not a COM library. That would be C++ classes, not C classes which are really just a struct.
If you know how to do this or have a link to a tutorial or sample code great that would be appreciated. How to access just global functions from a DLL is not needed.
Coding is a way of life. It's in the air we breath. It pumps through our veines. Without it we soon crumble to dust. - Rodney S. Foley
|
|
|
|
|
|
Nishant S wrote:
I seriously doubt if you can access native C++ classes from a C# program.
Nope, you can't. The problem is that each vendor compiles its C++ code differently, which is the main reason why COM was created (so that a binary standard existed for sharing OOP code without having to produce a version for every compiler version in existance)
As you said the best option is to use an MC++ wrapper for the native class.
James
Sig code stolen from David Wulff
|
|
|
|
|
Hello guys,
I have been only a few hours on C# and I am loving it.
I have created a program that downloads a web page, and i am trying to extract the keywords meta tag. I tried using the MSHTML stuff, but it was sooo slow! I figured that I will parse the meta keyword thing myself, thats when i discovered "regular expressions".
I have managed to the keywords from this kind of string:
However, the same pattern will not work on
(content and name are switched).
How cuold i make my query not care where CONTENT and NAME are located, as long as they ARE present in the string?
As usual,
Thanks in advance
Jeremy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Use some combination along the lines of
((?<key>\w+)\s*=\s*(?<value>\w+)\s+)*
to pick up all the tags in a metatag into a GroupCollection, then find the one with CONTENT in the key field.
Disclaimer: I'm just playing with Regular Expressions myself and I could have this completely wrong, but I think it's good.
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
Jeremy Pullicino wrote:
I have been only a few hours on C# and I am loving it.
Glad to hear that
Jeremy Pullicino wrote:
How cuold i make my query not care where CONTENT and NAME are located, as long as they ARE present in the string?
I'm by no means a regex guru, but this one does the trick for me though it could probably be optimized.
<meta (name=\"(?<name>.*?)\" content=\"(?<content>.*?)\")|(content=\"(?<content>.*?)\" name=\"(?<name>.*?)\")>
Using the IgnoreCase and ExplicitCapture options that works on your example above.
Regular Expression Workbench (V1.03)[^] written by Eric Gunnerson is a good tool for testing regex's because of the tooltip help breaking down what the regex does
HTH,
James
Sig code stolen from David Wulff
|
|
|
|
|
I forgot to point out that mine is very picky; so a cross between my solution and Paul's would probably be best
James
Sig code stolen from David Wulff
|
|
|
|
|
James T. Johnson wrote:
a cross between my solution and Paul's would probably be best
I was about to say that
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
I did a mix between paul's and mine and it worked like a charm Thanks guys.
My next step is to get this into an array or something (I need to store it in a database)
"word1,word2,word3 and four,word5"
Will regular expressions work well for this, or is it better if I use conventional string parsing?
Jeremy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
I think string parsing would be better for that. Use the Split method of the string class to get the initial array, then do parsing on each item to see if it contains more keywords (like 3 and 4 above).
James
Sig code stolen from David Wulff
|
|
|
|
|
If it's always going to look like that ("word1,word2,word3 and four,word5") then use String.Split on "," because it's a LOT more efficient.
If there's randomly spaces (like "word1, word2 , word3 and four,word5") then use Regex.Split on "\s*,\s*".
Paul
Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
|
|
|
|
|
The easiest thing is probably to write two separate regular expressions, and see if either of them match.
For using regex, you might want to download my utility:
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=regular%20expression%20workbench
|
|
|
|
|
Hi,
Does anyone know the equivalent APIs or mechanisms of doing
InvokePaint or InvokePaintBackground in Controls?
I want to tell a parent control to redraw itself inside the
control's client area, so it looks like a control can be
have "transparent" background (of course, not real transparent).
However InvokePaint is a protected method. There is no chance for
me to use these methods if I'm not inheriting the control class.
Thanks
Li-kai Liu
|
|
|
|
|
Ummm. If you are writing a control, you should be inheriting from the control class. Thus, you should have the ability to call the InvokePaint method.
Some more specifics might be nice if we're going to solve your problems.
Norm Almond: I seen some GUI's in my life but WTF is this mess
Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough
Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children
Leppie:My sister is 25
-Norm on the MailMagic GUI
|
|
|
|
|
That's what I don't want it to be at the moment...
I know I have to inherit the control class in order to
use it (because it's protected method...)
Currently, I'm writing many custom controls that each of
them requires this functionality. Therefore, I think
it's a good idea to "extract" this method as an external
one so that every control I've written could use it by
calling this external function, something like:
public static void DrawParentBackground(Graphic g, Control parent, Control callerControl)
No inheritance is involved in order to use these protected method...
Thanks again
|
|
|
|
|
Well, maybe still not very clear in my previous reply.
I included a picture of the button control I've been
writing for fun.
http://www.ykliu.com/problem.png[^]
It's a small button that draw everything from scratch. I plan a
few features for this button:
- support theme automatically. done! (Thanks for help from James T. Johnson)
- support shadowed text. done! (Thanks for great tutorials from Christian Graus)
- to able to draw underlying control, so it looks like transparent background is supported.
Well, that's why I come up with this question.
Though, I am able to use InvokePaint, InvokePaintBackground to redraw the
underlying parent control. Suddenly this question comes to my mind. If
I want to write another custom control that use this feature by using
InvokePaint. There is no way but inheriting it from Control Class.
Wouldn't it be better if I can write a static function, passing the caller
control and caller's parent control as parameter, then the function will
repaint caller control with the underlying parent's background.
Thanks in advance...
P.S. there's also another painting problem I found. illustrated in the included image.
Li-kai Liu
|
|
|
|
|
Can anyone show an example of using the Win32 SendInput function in C#? It seems to be missing from dotnet and I need to send a keyboard event,
thanks
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Google!
link[^]
How low can you go ? (MS retrofuck)
|
|
|
|
|
I saw that google link, and I've been working on it, but I still can't get it to work. I've reached the point where it neither throws errors, nor works.
My definitions are like this:
<br />
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]<br />
private static extern uint SendInput(<br />
uint nInputs,
INPUT[] pInputs,
int cbSize
);<br />
<br />
public struct INPUT {<br />
public int type;<br />
public short wVk;<br />
public short wScan;<br />
public int dwFlags;<br />
public int time;<br />
public UIntPtr dwExtraInfo;<br />
private int _pad0, _pad1;<br />
}<br />
<br />
I call it like this:<br />
<br />
INPUT[] ipar=new INPUT[1];<br />
INPUT m=new INPUT();<br />
ipar[0]=m;<br />
m.type= 1;
m.wVk= 0x41;
m.wScan= 0; <br />
m.dwFlags=0;<br />
m.time=0;<br />
uint u=0;<br />
m.dwExtraInfo=(System.UIntPtr)u;<br />
tbx.Focus();
uint ui=SendInput(1,ipar,System.Runtime.InteropServices.Marshal.SizeOf(m));<br />
<br />
the result is that ui = 1. But the Textbox stays empty.
I also tried it by doing the union inside the INPUT and making structs for hardware and mouse input, and I got that to the same point, where ui=1 but the textbox stays empty. This always what happens to me with com interop I get to the point where there's no errors but doesn't work.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Hi
I think your txtbox is not getting the focus. I have had problems before. You mite need to invoke the Focus method.
Hope this helps
"There are no stupid question's, just stupid people."
|
|
|
|
|
er I did invoke the Focus method, take another look at the code. Also, I know it's focused because i can see the cursor blinking in it, and the border etc..
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|