|
I'm developing a chart library with C# that outputs a SVG (Scalable Vector Graphic) file. SVG is pure XML output so there are no WinForms involved whatsoever.
In order to avoid overlapping text I'd like to use the MeasureString(...) and then set text properties (font size) accordingly, if overlap occurred. The Graphics object seems to be a prerequisite as it provides MeasureString(...). Is there a way of using MeasureString(...) functionality without using Graphics.
I've seen a possible solution which creates a random Graphics object out of a Bitmap which can then be "abused" to provide MeasureString(...) functionality:
<br />
Bitmap bmp = new Bitmap(1,1); <br />
Graphics g = Graphics.FromImage(bmp); <br />
g.MeasureString(...)<br />
Would you call this an elegant solution or is it just a workaround?
Once again: Is there another possibility of calculating the width of a string without Graphics?
Cheers.
|
|
|
|
|
Hello
I don't know about SVG formats but isn't displaying the text without overlapping would be the problem of the form that will read the file??
Anyway, if you want a graphics object, you don't need a bitmap, simple make call CreateGraphics() from your form -you still got one, right?-, and it will return a graphics object to work with.
Regards
|
|
|
|
|
Hello,
thanks for your reply.
Let me make things clearer.
SVG is a vector graphics format based on XML. The .NET application I'm currently developing generates such a SVG file. In this file various shapes, text elements, paths are described. Once the file is created the job is done.
As mentioned there are also text elements in the SVG, e.g. "This is a text" rendered as Arial, Bold, 12pt. MeasureString(...) would be ideal to calculate the size of any text although I'm eventually creating a SVG file.
Bear in mind: There is no form involved, so CreateGraphics() can't be invoked. Any further advice?
Thanks
|
|
|
|
|
Well, I guess then that you are developing a dll.
Even if there is no forms in your application, you can reference to System.Windows.Forms namespace and use TextRenderer class. There is a static method called MeasureText() that does the same thing.
Regards
|
|
|
|
|
You are right, I'm developing a dll.
Unfortunately, I'm using .NET Framework 1.1 - there isn't such a class available. Any other ideas?
Thanks.
|
|
|
|
|
|
Just tried .NET Framework 2.0 on a different machine. TextRenderer does it's job, thanks for your advice. Although the result is not that precise (same with MeasureString(...)) - I might provide my own method to measure strings. Anyway, I'll let you know!
Cheers.
|
|
|
|
|
Hi,
I have got the AppBar code running in a project sucessfully but the bar is always anchored to the top of my screen - I would like to have a button that will anchor the AppBar to the bottom of my screen on the taskbar.
I've been looking at the code and i'm not exactly sure what I have to change to make the AppBar locate to the bottom of the screen.
I was wondering if it was this section?
// Move and size the appbar so that it conforms to the
// bounding rectangle passed to the system.
MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true);
Is there any chance someone could help me or point me in the correct direction on how I can do this?
Many Thanks,
Al
|
|
|
|
|
Hi all
I’ve created a simple windows service and successfully installed it using installutil.exe (.NET Framework 2.0 version). I want the service to run under the Local System account. When I attempt to start the service in SCM I get “Could not start the ATS Application Monitor service on Local Computer. Error 5: Access is denied” (where ATS Application Monitor is the name of the service). If I go to the Log On tab of the service properties dialog and change the logon account to my current user logon (which has full admin rights) I can then start the service.
The Startup Type to Automatic. I tried rebooting the machine in hopes that it would start before user account login.
The service was developed under Visual Studio 5 using the Windows Service template wizard but I built the installer class from the example code I was working from (Recipe 14.7 of Visual C# 2005 Recipes: A Problem-Solution Approach).
Thanks Leyla:
|
|
|
|
|
How to read and write in Notepad (.txt files).
Thanks.
Vasildb
|
|
|
|
|
Grab the mouse in your preferred mouse hand.
Move the cursor (white arrow thingy) towards the bottom left corner of the screen.
Click the "Start" button
Click the "Run" menu
Type in "Notepad"
Click OK
Click File | Open
Open the required file
Edit the file
Click File | Save
Click File | Exit
As of how to accomplish this, have you ever tried Google? Failing that try
|
|
|
|
|
|
The cat ate my mouse! What should I do now?
only two letters away from being an asset
|
|
|
|
|
Ah, now that's a problem. It's much too complicated for exceptional people to understand.
The hardest solution would be to use the keyboard (by pressing wierd combinations).
The simplest solution would be to go out and buy another computer with an RS232 port, setup a serial mouse and then using scripts in Hyperterminal or a similar program to provide the necessary signals to move the mouse.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Just plug the cat into your computer. If your cat is plug'n'pray compatible, you should get a cat pointer instead of the mouse pointer, but it works the same.
---
b { font-weight: normal; }
|
|
|
|
|
To my understanding, you meant, "How to read and write .TXT file". If so,
// READ
string readContent = System.IO.File.ReadAllText(string fileName) // .txt File name.
//WRITE
System.IO.File.WriteAllText(string fileName, string contentToWrite)
/******* PLEASE check the spelling and verify before using this snippet as I typed here whatever I remember. *****/
|
|
|
|
|
Is there a way to take a array of bytes and run those bytes as a program without saving them to any type of disk, only run those bytes form memory?
|
|
|
|
|
Yes
As of how to accomplish this, have you ever tried Google? Failing that try
|
|
|
|
|
EscKey2004 wrote: d run those bytes as a progr
Are those array of bytes a .NET program? If so, yes, you can run them from memory using System.Reflection.Assembly.Load
|
|
|
|
|
I have tried this I built a little test app that looks like this but I really did not get much of a response from the stuff I tried loading is there something I am doing wrong?
OpenFileDialog open = new OpenFileDialog();<br />
if (open.ShowDialog() == DialogResult.OK)<br />
{<br />
System.IO.FileStream st = new System.IO.FileStream(open.FileName.ToString(), System.IO.FileMode.Open);<br />
System.IO.BinaryReader br = new System.IO.BinaryReader(st);<br />
byte[] bytes = new byte[br.BaseStream.Length];<br />
br.Read(bytes, 0, bytes.Length);<br />
<br />
System.Reflection.Assembly a = System.Reflection.Assembly.Load(bytes);<br />
a.CreateInstance(a.GetType().ToString());<br />
}
|
|
|
|
|
Are you getting some exception with that code? What exactly doesn't work?
|
|
|
|
|
On some things I get a exception that looks like this, but then on some things it just dosent do anything.
"Could not load file or assembly '1453384 bytes loaded from asmTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."
|
|
|
|
|
i just started a socket application that recieves UDP data. The data that i am recieving is a netflow packet from cisco devices. to learn how to do this i have been searching the forums and looking at other people's code for reference. some code that i came across was the following. pretty much what you do is, passed a byte[2048] to the procedure ToUInt and specify the starting point to get the datafield in the byte and the length from that starting position to get. the first field in the packet is the version field which starts at position 0 and is 16 bits long. so you would end up passing to the following code the byte[2048] of your data buffer, 0 for your offset and 16 for your length. i understand mostly all of the code except that part there the Shift Right occurs and the ANDing against 0x0001.
b is 10, and then after the bitwise operations is it 5. which is the correct version number for the netflow packet that my application recieved.
public static uint ToUInt(byte[] datagram, int offset, int length) {
uint total = 0;
int byte_index;
int bit_offset;
int bit;
byte b;
for ( int i = 0; i < length; i++ ) {
bit_offset = (offset+i) % 8;
byte_index = (offset+i-bit_offset) / 8;
b = datagram[byte_index];
bit = (int)(b >> (7 - bit_offset));
bit = bit & 0x0001;
if ( bit > 0 ) {
total += (uint)Math.Pow(2,length-i-1);
}
}
return total;
}
i modified the code to print to a console the values of each variable during each iteration of the loop. here are the values.
i bit_offset byte_index b bit total
0 0 0 0 0 0
1 1 0 0 0 0
2 2 0 0 0 0
3 3 0 0 0 0
4 4 0 0 0 0
5 5 0 0 0 0
6 6 0 0 0 0
7 7 0 0 0 0
8 0 1 5 0 0
9 1 1 5 0 0
10 2 1 5 0 0
11 3 1 5 0 0
12 4 1 5 0 0
13 5 1 5 1 4
14 6 1 5 0 4
15 7 1 5 0 5
i relize that the byte_index is just a counter for how many bits you have iterated through. once you went through 8 bits, incriment the byte index by 1. since the length is 16, that is two bytes and that would account for 0, and 1. i is just the counter set to the length of 16. i don't understand the B, bit, and total values. could someone explain the logic behind this to me?
|
|
|
|
|
I have added comments to part of the code:
bit_offset = (offset+i) % 8;<br />
<br />
byte_index = (offset+i-bit_offset) / 8;<br />
<br />
b = datagram[byte_index];<br />
<br />
bit = (int)(b >> (7 - bit_offset));<br />
<br />
bit = bit & 0x0001;<br />
<br />
total += (uint)Math.Pow(2,length-i-1);<br />
---
b { font-weight: normal; }
|
|
|
|
|
hey thanks a lot. this is helpful
|
|
|
|