|
guess0985 wrote: sometimes it inserts record in data base and sometimes it says file not found (error 404).why is this happening.... Plz help?
The 404 indicates that the webserver is the origin, not the database-server. Can you copy the exception and post it here?
You might also want to consider replacing the concatenated SQL-string with a parameterized version to prevent abuse via SQL injection[^].
I are Troll
|
|
|
|
|
Hi,
I am wondering if anyone coul help. I need use the paint event of a control to retun an image of that control.
I dont even know where to start.
Regards,
Martin
|
|
|
|
|
Martin Beukes wrote: I need use the paint event of a control to retun an image of that control.
I don't think so.
Either you want some special painting to occur in a Control, then you have to implement a Paint handler (this[^] would show the essentials), or you want a bitmap from an existing Control, then you would use Control.DrawToBitmap() which works fine for simple Controls, and needs quite some help for some Controls, such as RichTextBox (DrawToBitmap probably does call Paint itself, but that is not really relevant).
|
|
|
|
|
Hi Luc,
It is almost af if you can read minds. It is a richtextbox that i need an image of. There is no Control.DrawToBitmap() on the control and i have looked pretty much everywhere. I came accross this article [Here] which gave me the idea but none of the execution.
If you know of any way to get an image of a RichTextBox without using a screen capture, it would be much appreciated.
|
|
|
|
|
Just to make sure, here are my assumptions:
you have a RichTextBox, you did not add any explicit Paint or OnPaint method, it shows OK on the screen, but now you want to capture it to a bitmap without scraping the screen? if so I have that covered in C#. Is that OK?
BTW: why do you want a bitmap? and do you need printing?
modified on Monday, January 11, 2010 6:09 PM
|
|
|
|
|
Ok,
I have 2 RTB with diffent contents
I need to print these two RTBs contents on a single page
My plan is to use the GDI to an image of each RTB and then cmbine and print them.
Now the problem. more tha half my users will be on those godaweful netbooks with a screen resolution of 1024x6 <lol> and an A4 page and the my two RTBs is 1045x718 plus margins. So the problem is that i need to capture the whole control and not just what is onscreen.
|
|
|
|
|
I see. That is typical for the more complex controls: they hold a lot of data, not all of it visible at once, and you want to print more or all of it. You can try and solve that through DrawToBitmap (when available and functional), however that isn't very easy to do it right; it might be easier to skip the image and print directly.
I have an RTB derivative that offers both: Print (not tested) and DrawToBitmap (tested and OK). It is C# code. Is that OK?
|
|
|
|
|
awesome. thanks. would help a ton
|
|
|
|
|
Here you go:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Drawing.Printing;
namespace LP_Core {
[System.ComponentModel.DesignerCategory("Code")]
class LP_RichTextBox : RichTextBox {
private const double anInch = 14.4;
[StructLayout(LayoutKind.Sequential)]
private struct RECT {
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct CHARRANGE {
public int cpMin;
public int cpMax;
}
[StructLayout(LayoutKind.Sequential)]
private struct FORMATRANGE {
public IntPtr hdc;
public IntPtr hdcTarget;
public RECT rc;
public RECT rcPage;
public CHARRANGE chrg;
}
private const int WM_USER = 0x0400;
private const int EM_FORMATRANGE = WM_USER + 57;
[DllImport("USER32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
public int Print(int charFrom, int charTo, PrintPageEventArgs e) {
RECT rectToPrint;
rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);
RECT rectPage;
rectPage.Top = (int)(e.PageBounds.Top * anInch);
rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
rectPage.Left = (int)(e.PageBounds.Left * anInch);
rectPage.Right = (int)(e.PageBounds.Right * anInch);
IntPtr hdc = e.Graphics.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = charTo;
fmtRange.chrg.cpMin = charFrom;
fmtRange.hdc = hdc;
fmtRange.hdcTarget = hdc;
fmtRange.rc = rectToPrint;
fmtRange.rcPage = rectPage;
IntPtr res = IntPtr.Zero;
IntPtr wparam = IntPtr.Zero;
wparam = new IntPtr(1);
IntPtr lparam= IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lparam, false);
res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);
Marshal.FreeCoTaskMem(lparam);
e.Graphics.ReleaseHdc(hdc);
return res.ToInt32();
}
public void DrawToBitmap(Bitmap bitmap) {
RECT rectToPrint;
rectToPrint.Top = 0;
rectToPrint.Bottom = (int)(bitmap.Height*anInch);
rectToPrint.Left = 0;
rectToPrint.Right = (int)(bitmap.Width*anInch);
RECT rectPage;
rectPage.Top = 0;
rectPage.Bottom = (int)(bitmap.Height*anInch);
rectPage.Left = 0;
rectPage.Right = (int)(bitmap.Width*anInch);
Graphics g=Graphics.FromImage(bitmap);
IntPtr hdc = g.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = -1;
fmtRange.chrg.cpMin = 0;
fmtRange.hdc = hdc;
fmtRange.hdcTarget = hdc;
fmtRange.rc = rectToPrint;
fmtRange.rcPage = rectPage;
IntPtr res = IntPtr.Zero;
IntPtr wparam = IntPtr.Zero;
wparam = new IntPtr(1);
IntPtr lparam= IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lparam, false);
res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);
Marshal.FreeCoTaskMem(lparam);
g.ReleaseHdc(hdc);
}
}
}
Please let me know the results when they become available, and/or any changes you consider necessary.
|
|
|
|
|
The PaintEventArgs are of no use, but you can call DrawToBitmap on the Control as Luc suggested in your Paint handler... something like this (untested):
private void Control_Paint(object sender, PaintEventArgs e)
{
Control control = sender as Control;
if (control != null)
{
using(MemoryStream memoryStream = new MemoryStream())
using (Bitmap bitmap = new Bitmap(memoryStream))
{
control.DrawToBitmap(bitmap, control.Bounds);
}
}
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
My company wants to allow users to scan test answer sheets from our web site and use OMR to score these tests. I have created a control that provides this functionality using VS 2008 (in VB.) I am able to embed the control using the object tag and classid attribute. To be able to do use this from a remote computer I have to use the .net 2.0 configuration app and add a codegroup for our website allowing full trust for code coming from our sitename and install an Access database on the machine. Using the 'Create Deployment Package Wizard' I was able to create a .msi file that (i think) replicates my settings/codegroup.
I have been able to get this to work on 5/6 machines I have tried but only a couple of them were simple (run the msi, add website as a trusted site, restart IE.) The other 2-3 I had to fool around with and do things like add the control to the GAC or manually add the code group and one of the machines is still unable to use the control.
I am hoping someone has an idea for a better deployment solution. I assume there is a way to incorporate the permissions setup, the database installation, and even framework installation into a single setup file/setup wizard but my biggest concern is reliability. Relying on the msi doesn't seem effective enough for release, especially since some clients will not have the .net 2.0 config as a backup.
I know a lot of my troubles are coming from the fact that I am trying to do something I shouldn't be doing. I read this similar post suggesting that the object be redone as an activex control so that IE will automatically ask the user:
http://social.msdn.microsoft.com/Forums...
Is activex the only viable solution here or is there something else that can be done? Our users will be willing to install whatever it takes on their machine so it doesn't need to be a 'click once' type of deployment at all. I have never worked with activex (or WCF for that matter.) If that is our only option is there a way to build the vb.net control i have as an activex control? From my early research i thought i found that .net doesn't support active x as it is being phased out by wcf so would i need to convert everything to VB6?
Sorry for such a long question filled post. I do appreciate any input or answers you have and I am willing to read articles or do research if you have links, i just seem to be hitting dead ends with my own searches.
|
|
|
|
|
sitruc7 wrote: Is activex the only viable solution here or is there something else that can be done?
I'd recommend to sign the code with a certificate that's trusted by the browsers that your clients have. There's also a post on 15 seconds[^] with more information on the Code Access Permissions that could help.
Alternatively, you could try embedding it using WPF[^].
I are Troll
|
|
|
|
|
Hello.
I'm using ADO.Net data services and i'm trying to do some kind of API to access to a data base in a remote server, execute a querie there and bring the data to me.
What i have to use, and how?
If you know some place with examples(code) send me the links.
Thank´s. When i finish i will share the code with everyone.
Wonderfull 2010 for everyone.
|
|
|
|
|
You don't need to do anything in your code. Set up your database to allow remote connections. You can do this using Surface Area Configuration in your server.
Then, look for connection string for a remote database in ConnectionStrings.com and you are done.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hi
Thanks for your reply. I will try your advices. When I've done i will tell you.Thanks
(By the i'm portuguese so, excuse my english )
|
|
|
|
|
Hi,
Im working with some programmers on a project. We are creating a software piece and have some problems with form/table design. Im trying to take the technical look out of the form and give it a more designed look. I have included a screen shot.
What I want to do is:
1. Design the header of the table.
2. Create alternate row colours
3. Use Grapical buttons instead of the Edit Delete Buttons.
I have tried looking for skins etc for tables, but no luck. While Im not experienced in VB.net I have a team that is. Im just looking for someone to point me in the right direction. Thanks for any help.
Kind Regards,
Thomas
|
|
|
|
|
Thomas O'Donoghue wrote: While Im not experienced in VB.net I have a team that is
Are you sure they are? They should know how to do these common tasks. Most of these are properties of tables in .net, so are easy to implement.
Bob
Ashfield Consultants Ltd
Proud to be a Code Project MVP
|
|
|
|
|
hi......
i just want to convert an arraylist into bytearray via object in clientside and again convert this bytearray into arraylist in server side.could somebody help me on this.
i tried a lot.
the arraylist contents are from a file whose name is obtained in client.
but i could not get the answer.
i would be thankful to you...
my codings are as follows:
Server:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication1
{
[Serializable]
class Program
{
static void Main(string[] args)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Bind(ip);
s.Listen(10);
Console.WriteLine("Waiting for a client...");
Socket cli = s.Accept();
IPEndPoint cliep = (IPEndPoint)cli.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", cliep.Address, cliep.Port);
byte[] buffer = new byte[1024];
cli.Receive(buffer);
string fname = Encoding.ASCII.GetString(buffer);
Console.WriteLine("filename is " + fname);
Console.ReadLine();
byte[] buf = new byte[1024];
cli.Receive(buf);
Object obj = new Object();
obj = bytearraytoobject(buf);
ArrayList al = obj as ArrayList;
int i = 0;
foreach (Object o in al)
{
Console.WriteLine("\t[{0}]:\t{1}", i++, o);
}
Console.WriteLine();
Console.ReadLine();
}
static Object bytearraytoobject(byte[] buffer)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
ms.Write(buffer, 0, buffer.Length);
ms.Seek(0, SeekOrigin.Begin);
Object obj = (Object)bf.Deserialize(ms);
return obj;
}
}
}
client:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication2
{
[Serializable]
class Program
{
static void Main(string[] args)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
s.Connect(ip);
}
catch (SocketException e)
{
Console.WriteLine("Unable to connect to server" + e);
return;
}
Console.WriteLine("Enter the input file ");
string inp = Console.ReadLine();
s.Send(Encoding.ASCII.GetBytes(inp));
StreamReader sr = new StreamReader(@"c:\" + inp);
ArrayList al = new ArrayList();
while (!sr.EndOfStream)
{
al.Add(sr.ReadLine());
}
Object o = (Object)al;
byte[] buffer = new byte[1024];
buffer = objecttobytearray(o);
s.Send(buffer);
Console.ReadLine();
}
static byte[] objecttobytearray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}
|
|
|
|
|
you should edit your post and add PRE tags to that code in order to get it formatted so anyone could read it.
|
|
|
|
|
thank you very much for ur kind reply........
i have worked on it and found the solution by myself.
anyway please help me on my later questions regarding my doubts in .net.......
actually it is to generate some random questions by sending the file contenets from client to server and then the server should generate random questions(say 5) from it and the send back to the client.....
THANKS FOR THIS...
ADVANCE THANKS to answer for my later questions.
my code is as follws:
Server:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Bind(ip);
s.Listen(10);
Console.WriteLine("Waiting for a client...");
Socket cli = s.Accept();
IPEndPoint cliep = (IPEndPoint)cli.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", cliep.Address, cliep.Port);
byte[] buffer = new byte[1024];
cli.Receive(buffer);
string fname = Encoding.ASCII.GetString(buffer);
Console.WriteLine("filename is " + fname);
Console.ReadLine();
cli.Receive(buffer);
Object obj = new Object();
obj = bytearraytoobject(buffer);
ArrayList al = (ArrayList)obj;
int i = 0;
foreach (Object o in al)
{
Console.WriteLine("\t[{0}]:\t{1}", i++, o);
}
Console.WriteLine();
ArrayList qal=new ArrayList();
Random rnd = new Random(DateTime.Now.Millisecond);
for (int counter = 0; counter < 5; counter++)
{
int randomindex = rnd.Next(al.Count);
Console.WriteLine("{0}:{1}", counter+ 1, al[randomindex]);
qal.Add(al[randomindex]);
}
foreach (Object o in qal)
{
Console.WriteLine("\t[{0}]:\t{1}", i++, o);
}
Object ob = (Object)qal;
buffer = objecttobytearray(ob);
cli.Send(buffer);
Console.ReadLine();
}
static Object bytearraytoobject(byte[] buffer)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
ms.Write(buffer, 0, buffer.Length);
ms.Seek(0, SeekOrigin.Begin);
Object obj = (Object)bf.Deserialize(ms);
return obj;
}
static byte[] objecttobytearray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}
client:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
s.Connect(ip);
}
catch (SocketException e)
{
Console.WriteLine("Unable to connect to server" + e);
return;
}
Console.WriteLine("Enter the input file ");
string inp = Console.ReadLine();
s.Send(Encoding.ASCII.GetBytes(inp));
StreamReader sr = new StreamReader(@"c:\" + inp);
ArrayList al = new ArrayList();
while (!sr.EndOfStream)
{
al.Add(sr.ReadLine());
}
Object o = (Object)al;
byte[] buffer = new byte[1024];
buffer = objecttobytearray(o);
s.Send(buffer);
byte[] buf = new byte[1024];
Object obj = new Object();
s.Receive(buf);
obj = bytearraytoobject(buf);
ArrayList qal = (ArrayList)obj;
int i = 1;
foreach (Object ob in qal)
{
Console.WriteLine("\t[{0}]:\t{1}", i++, ob);
}
Console.WriteLine();
Console.ReadLine();
}
static byte[] objecttobytearray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
static Object bytearraytoobject(byte[] buffer)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
ms.Write(buffer, 0, buffer.Length);
ms.Seek(0, SeekOrigin.Begin);
Object obj = (Object)bf.Deserialize(ms);
return obj;
}
}
}
|
|
|
|
|
I have researched adding a MessageBox to an application. However the sealed class does not give you much. The solution is always to create your own.
I figure you could use the Win32 Version and import it into C#. but that does not take care of the background color. in MFC you call setdlgBackColor or something like that and the entire application is converted to the new color (skin).
in C# you do not have that. is this exposed in VB.NET? I was thinking I could link in a VB.NET DLL with the functionality.
still there are several dialogs in windows that act this way. one of them is the fileopen dialog.
does anyone have an elegant solution that does not involve recoding the entire functionality, LOL, of the dialog / MessageBox in question? there are many people on the web running into this problem, especially if they are skinning their apps or providing custom colors for customer requirements.
Thanks
-Pete
|
|
|
|
|
|
This is a great Article - Thanks!
I could not figure out how to change the background color though.
I did not see anything in the code of the project that allowed you to do that.
-Pete
|
|
|
|
|
peterdrozd wrote: I could not figure out how to change the background color though.
You could try posting your question on the article forum to see if the author has any idea. I suspect you may find it quicker just to use a custom dialog with all your own controls and formats.
|
|
|
|
|
You must have to write a custom control to do that...
|
|
|
|
|