|
I'm creating graphical controls. They use an image as a source and break that image up into top, bottom and the fill area:-
|---|------|---|
| L | F | R |
|___|______|___|
Left is copied to 0,0
Fill is turned into a textureBrush and tiled to fill the text area
Right is copied to the end of the text area.
Hence i need to know the size the text will occupy when rendered. The horizontal works fine. The problem I have is that the vertical (Using Top, Fill, Bottom) is returning a size that is too small so that when the text is drawn it goes outside the fill area.
It seems that .MeasureString is not taking something into account when measuring vertical text. The 1.6 difference becomes 1.4 at a higher resolution so I am assuming i missed a setting somewhere so its returning em's and not pixels.
IT'S DOING MY HEAD IN
|
|
|
|
|
Private Function VerticalGenerate() As Bitmap
Dim TopRect As Rectangle = _Style.Section1
Dim BottomRect As Rectangle = _Style.Section2
Dim TextArea As SizeF
Dim g As Graphics = Graphics.FromImage(Style.SourceImage)
'If Not _Text = "" Then
'calculate text area
Dim tb As New TextBuilder()
TextArea = tb.GetTextArea(g, _Style.txtStyle, _Text, New StringFormat(StringFormatFlags.DirectionVertical))
TextArea.Height = TextArea.Height * 1.4
'End If
'create target bmp
Dim bmp As New Bitmap(TopRect.Width, Convert.ToInt32((_Style.Offset.Top + Style.Offset.Bottom) + (TextArea.Height)))
g = Graphics.FromImage(bmp)
g.DrawImage(Style.SourceImage, TopRect, TopRect, GraphicsUnit.Pixel)
'calculate bottom position
Dim temprect As Rectangle = BottomRect
temprect.Offset(New Point(0, (bmp.Height - BottomRect.Height) - BottomRect.Top))
'draw bottom
g.DrawImage(Style.SourceImage, temprect, BottomRect, GraphicsUnit.Pixel)
'do fill
Dim temprect2 As Rectangle = New Rectangle(0, TopRect.Height, TopRect.Width, _Style.ImageSize.Height - (TopRect.Height + BottomRect.Height))
FillArea(g, Style.SourceImage, temprect2, New Size(TopRect.Width, TextArea.Height), New Point(0, TopRect.Height), WrapMode.Tile)
'bmp.Height - (TopRect.Height + BottomRect.Height)
If Not _Text = "" Then
Dim Sf As New StringFormat()
Sf.FormatFlags = StringFormatFlags.DirectionVertical Or StringFormatFlags.NoWrap
tb.RenderText(g, _Style.txtStyle, _Text, New RectangleF(0, TopRect.Height, TextArea.Width + 1, TextArea.Height), Sf)
' New RectangleF(0, TopRect.Height, TopRect.Width, bmp.Height - (TopRect.Height + BottomRect.Height))
Sf.Dispose()
End If
Return bmp.Clone
g.Dispose()
bmp.Dispose()
End Function
Public Function GetTextArea(ByRef g As Graphics, ByRef Style As TextStyle, ByVal Text As String, ByVal strFormat As StringFormat) As SizeF
Return g.MeasureString(Text, Style.FontFace, New SizeF(1000, 1000), strFormat)
End Function
Public Sub RenderText(ByRef g As Graphics, ByRef Style As TextStyle, ByVal Text As String, ByVal TargetRect As RectangleF, ByRef Format As StringFormat)
If Not Style.Texture Is Nothing Then
g.DrawString(Text, Style.FontFace, Style.Texture, TargetRect, Format)
ElseIf Not Style.Gradient Is Nothing Then
g.DrawString(Text, Style.FontFace, Style.Gradient, TargetRect, Format)
Else
g.DrawString(Text, Style.FontFace, New SolidBrush(Style.ForeColour), TargetRect, Format)
End If
End Sub
|
|
|
|
|
I have a text file with unicode strings (T H I S I S A S T R I N G) and I want to search for those strings and convert them to ascii.
How do I use string.IndexOf for a unicode value? Say I want to search for:
file.IndexOf(Encoding.Unicode.GetBytes("http://"));
which obviously doesn't work since there is no byte[] overload. So how do I convert an ascii string to a unicode string?
All I really need I guess is how to get "http://" converted to "h\0t\0t\0p\0:\0/\0/\0" and back.
|
|
|
|
|
Here's my scenario:
I want a client application to connect to my webservice and request a particular file, which I'll stream down to them.
Client would then save to disk on their side.
Returning a byte[] seems the best option, but I'm not too sure how to get the encoding right so the resultant file is still valid.
The files in question would be binary.
Anyone done this?
Cheers,
Simon
"I ask candidates to create an object model of a chicken.", Bruce Eckel on interviewing programmers.
animation mechanics in SVG (my first abstract photo)
|
|
|
|
|
|
There is a text editor I like to use on Linux called Kate, part of KDE. It has a nice feature where you can have a command prompt in a frame, and the command prompt "follows" the document you are currently editing.
I was thinking it would be nice to have something like this on Windows. But I can't see any way to embed a command prompt in a C# Windows Form.
Does anyone know if this is possible, and if so how to do it? Any ideas?
|
|
|
|
|
imoz wrote:
Does anyone know if this is possible, and if so how to do it? Any ideas?
Yes, see the documentation for the System.Diagnostics.Process; probably there are samples for this on the Internet already.
You'll need to provide alternate input/output StreamWriters on the StandardOutput and StandardInput properties, redirecting it to where you may want.
Kant wrote:
Actually she replied back to me "You shouldn't fix the bug. You should kill it"
|
|
|
|
|
Hi there,
Thanks for the tip. I was able to track down some samples. I am able to start a cmd.exe process w/ no window. However, if I put a textbox on my windows.form, and setup an event handler for the KeyPress event, it hangs when I try to write e.KeyChar to the stream.
Joe Mozelesky
:: powered by imoz ::
"Luck is the result of preparation and opportunity."
|
|
|
|
|
imoz wrote:
Hi there,
Thanks for the tip. I was able to track down some samples. I am able to start a cmd.exe process w/ no window. However, if I put a textbox on my windows.form, and setup an event handler for the KeyPress event, it hangs when I try to write e.KeyChar to the stream.
Maybe the process isn't waiting for a char at the moment you sent the key to its input stream.
One thing I would try would be using a buffered stream or a separate thread that read the chars from a queue.
Kant wrote:
Actually she replied back to me "You shouldn't fix the bug. You should kill it"
|
|
|
|
|
Hi,
I like to create something like the explorer tree. This treeview structure contains more than one node type (drives, systemcontrol, network). Each node type has it's own behaviour, and has to be handled different. Letz say some content are the drives of the local machine, but another node type represents no disk drive (e.g SystemControl) that is handled different as if you click on a drive node.
How to handle stuff like that? The goal should be to reuse my node handler's, so i don't like to implement all the stuff in one special treeview class. I guess i have to write something like NodeHandler's, which only handles the events from the node type it made for.
For my explorer view i would have 3 NodeHandlers, one for drives, one for systemcontrol and one for network, right ?
if you know a good pattern to handle this, please let me know
.:[Greets from Jerry Maguire]:.
|
|
|
|
|
I would like to draw text with a OPAQUE or TRANSPARENT backgound mode.
How to do that with GDI+?
In other terms, under GDI+, how to obtain an effect similar to the SetBkMode and SetBkColor functions of GDI?
|
|
|
|
|
hi there,
Just a quickie:
Are there classes around to directly convert a 4byte big byte array to an Int32, or do I need to go the manual way?
Thanks a lot,
stonee
|
|
|
|
|
byte bt=0;
int i = Convert.ToInt32(bt);
MessageBox.Show(i.ToString());
switch(twinsOnWay)
{
case ("twins on the way"):
MessageBox.Show("for mr and mrs dynamic","twins on the way");
break;
|
|
|
|
|
i am talking about a byte array consisting of 4 bytes!
thanks,
stonee
|
|
|
|
|
have you checked out Convert Class,
it offers great varieties
|
|
|
|
|
found a solution with the
System.BitConverter.ToInt32(mybyteArray,4);
thanks anyway,
stonee
|
|
|
|
|
Hey,
I have a Windows form apllication with form1 and form2.
Form1 :
Combobox1 : bind to a dataset and have a displaymemeber
and valuemember.
Button1 : to go to form2 and also save the
combobox1.selectedvalue in a static variable string (ex.
val).
Form2 :
Combobox2 : bind to the same dataset, dislaymember and
valuemeber like combobox1 (When i checked it have the
same contents like combobox1).
But here I want to set the selectedvalue = val (the
selectedvalue of Form1.combobox1 saved in memory).
I'am sure that combobox2 have a selectedvalue=val.
But after combobox2.SelectedValue = val; The
selectedvalue of combobox2 stays null.
I don't know why.
Somebody knows the reason?
Set the selectedvalue of a combobox works fine, if i stay
on the same form, with the same combo. (So the combo is not constructed in the initialisecomponent again)
Nic
|
|
|
|
|
I Founded (after a several houres).
Fault was I bound the data and valuemebers in de initialisecomponent. It must be in the constructor !!!!
|
|
|
|
|
Hey,
In a Windows Form I access the assembly as follows :
Assembly assem = this.GetType().Assembly;
foreach(string resourceName in assem.GetManifestResourceNames(){
...
}
How I have to do that in a console application? This application have only a Main.
In the Main you cannot use this (because Main is static).
But I will do the same thing like in the windows forms.
Thanks for the hints,
bell
|
|
|
|
|
Is there a way to manually remove a file lock?
|
|
|
|
|
A question concerning the behavior...
Ex. I bind the data to a DataSet in the Form_Load() event. I have an event that is triggered when on the SelectedIndex_Changed event. On the load, the DataBind is causing the SelectedIndex event to fire which sort of makes sense. Is there flag or property I can set around the code block which binds the data to force it not to trigger that event.
|
|
|
|
|
There's no flag like this, I think. Create Your own - or - disconnect handler before DataBind and connect it after loading data
Hi,
AW
|
|
|
|
|
It is because.first u are seting the data source and then u might be setting the dispaly member and value member....
u can do like this
cmbClassId.DisplayMember = dataSet.Tables[Constants.CLASSES].Columns["ClassName"].ToString();
cmbClassId.ValueMember = dataSet.Tables[Constants.CLASSES].Columns["ClassID"].ToString();
cmbClassId.DataSource = dataSet.Tables[Constants.CLASSES];
This will cause event to occure only once.
dipak
|
|
|
|
|
To make a long story short, I've had to reinstall the directX 9 SDK. Im having trouble though actually finding the .dll files I need to use however (Microsoft.DirectX.Direct3D.dll etc). In my C:\WINDOWS\Microsoft.NET\Managed DirectX\v4.09.00.0900 directory, I have all of the .dll files I have used before however for files like Microsoft.DirectX.Direct3D and Microsoft.DirectX.Direct3DX, which I havent used before, all I has is their .xml files (no .dlls). I know .xml files arent "executable" but I have a suspicion I can create the .dll files from the .xml files. Any ideas?
I dont know, this whole thing has me pretty confused. Ive uninstalled and reinstalled the sdk a few times now, and cannot figure out where its putting all those files. I dont remember having this problem the first time I installed the sdk, and now everything just seems to be messed up. Any ideas?
Thanks
Dave Ratti
|
|
|
|
|
All right nevermind, I seemed to have fixed it. I installed DirectX 9a and now all my .dll files are there. Still very weird though.
|
|
|
|
|