|
|
|
Hi,
Actually I made a user control that its interface is like "glass windows" in windows vista and seven.
My pattern was this picture[^]
using "Photoshop" and draw every layer with C# and .Net drawing classes, I finally draw it.
In first step, i create a bitmap class and then each layer will be drawn on it using graphic path and brushes and so on.
here is the control.glass panel[^]
(you must first add the "reflect.png" file to your project resources and then add class to project then build, ...)
OK,
my problem is the low efficiency of this control while moving and resizing parent form.
because this works, cause calling "draw" method of the control and when calling of method got a lot, it will be slow down the application and more important, it is very CPU hungry.
I want you to learn me a way to draw the user interface of this control
1-using dot net 2.0
2-efficient, like other windows controls.
is there a way to paint UI using directx,...?(I mean not WPF)
if there is no way, i will remove the reflect part of the code that causes high CPU using.
thank you.
modified on Monday, July 19, 2010 8:32 AM
|
|
|
|
|
Hi,
Most of our readers don't download archives to browse code, you'd get more replies if you'd add the code to the post (using PRE tags) I've included a small snippet of your code below for reference;
public void draw()
{
if (Width < 20 || Height < 20)
{
return;
}
Bitmap b = new Bitmap(Width, Height);
Graphics gr = Graphics.FromImage(b);
GraphicsPath gp=new GraphicsPath();
LinearGradientBrush br;
gr.SmoothingMode = SmoothingMode.HighSpeed;
for (int i = 0; i < 10; i++)
{
gp = DrawRoundRect(i, i, Width - i * 2 - 1, Height - i * 2 - 1, 7);
br = new LinearGradientBrush(Bounds, Color.FromArgb(i * 3, Color.Black),
Color.FromArgb(i * 3, Color.Black), LinearGradientMode.Vertical);
gr.DrawPath(new Pen(br, 4), gp);
br.Dispose();
}
On to your question; you're drawing in a dedicated method, called draw . This builds a bitmap in turn, and setting that as a backgroundimage.
You can paint directly on the canvas by overriding the Paint-handler;
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
} You can then use the Graphics object to draw directly to the canvas of the control.
Next, if your control needs redrawing, don't call the draw method, but call the Invalidate [^] method. Third tip would be to re-using objects like brushes and pens, as opposed to creating new ones each time you have to draw.
Hope this helps
I are Troll
|
|
|
|
|
thanks eddy.(i don't forget your recommendation about source code
i think i already done this. but the program crashed down.
because the paint event consecutive raise.
i will test it again and will report you.
thanks again.
(what about GPU, ...?)
i forgot it:
i want when the form moves, the control paint itself to draw reflect on the glass panel.
when you move form, you will see that the reflect is stable
modified on Monday, July 19, 2010 9:09 AM
|
|
|
|
|
mohammad_b wrote: because the paint event consecutive raise.
The method is called by Windows when it needs to repaint a part of the form. If you post your new paint-handler, we'll look at it
mohammad_b wrote: (what about GPU, ...?)
I'd recommend converting to WPF over trying to directly access the GPU. You could even create your own effects[^].
mohammad_b wrote: i want when the form moves, the control paint itself to draw reflect on the glass panel.when you move form, you will see that the reflect is stable
Yup, your life would be easier using WPF. Using WinForms, you'd have to Invalidate the control to force a repaint. I don't know how this will perform with a large area if you call this method in the OnMouseMove event. You'd have to give it a try to find out.
I are Troll
|
|
|
|
|
thanks again.
first i apologize for my dirty and ugly coding.
when i reopen the class codes and look at it, I ashamed from myself that what is this code that i written.
----
the paint method is good. i switched to it.
I remove all codes and just a simple border drawing code and glow shadow with a new and efficient method is remained.
it still is beautiful
----
now i can't switch to WPF. but it is in my learning progs
bye
|
|
|
|
|
mohammad_b wrote: thanks again.first i apologize for my dirty and ugly coding.
With pleasure, and don't apologize; your approach is logical if you haven't had to write a paint-handler before. A good effort, and a nice read.
My compliments on solving the issue
I are Troll
|
|
|
|
|
Hi ,
Inorder to get the shortname in vb.net I have written the following code .but it is returning null .Can you please help
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal longPath As String, ByVal shortPath As String, ByVal shortBufferSize As Int32) As Int32
Dim longPathName As String
longPathName = dest
Dim longPathLength As Int32 = longPathName.Length
Dim shortPathName As String = Space(longPathLength)
Dim returnValue As Int32
returnValue = GetShortPathName(longPathName, shortPathName,longPathLength)
MsgBox(shortPathName.ToString)
|
|
|
|
|
Try this one.
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
public static void Main()
{
StringBuilder shortPath = new StringBuilder(255);
GetShortPathName(@"D:\My Temp\ResourseProvider\sql.txt", shortPath, shortPath.Capacity);
Console.WriteLine(shortPath.ToString());
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
thanks 4 ur support
, but very sorry .Can you please give the code in VB.Net.
|
|
|
|
|
Please do not repost the same question.
You have already posted your question here[^] and got attention.
Please go through the forum posting guidelines[^].
And the code I have posted is in CSharp. So now you need to take
effort in just converting syntax buddy. So, from next time please
put some effort before posting anything on this forum.
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As StringBuilder, _
ByVal cchBuffer As Integer) As Integer
Public Function GetShortPath(ByVal longPath As String) As String
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New StringBuilder(requiredSize)
GetShortPathName(longPath, buffer, buffer.Capacity)
Return buffer.ToString()
End Function
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Bit harsh there.
I agree he should have stuck to the original thread (but he is new here), but that aside, he did try to convert your code to VB.Net, just not very succesfully. You posting (or should I say re-posting) in C# when you can see his question is in VB.Net is just as unhelpful. Some of us are code bi-lingual, but not everyone is.
We should be encouraging people to post better, not discouraging them from posting at all.
|
|
|
|
|
Ok, buddy.
I will keep in mind from next time.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
How to change the name of the datagrid column thru programs?
For example.
in the table pmast, rcpno is the name of a field. But in the datagrid, I want to display the column heading as Receipt No.
The code is as follows :
Private Sub viewbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles viewbtn.Click
Dim strconv As New OleDb.OleDbConnection(ds)
disallbtn()
binddv = New OleDb.OleDbDataAdapter("select rcpno, rcpdt ,pname from pmast order by rcpno", strconv)
If Not oledv.Tables("pmast") Is Nothing Then
oledv.Tables("pmast").Clear()
End If
binddv.Fill(oledv, "pmast")
DataGridView1.DataSource = oledv.Tables("pmast")
DataGridView1.Show()
DataGridView1.Focus()
End Sub
|
|
|
|
|
Try this -
Dim myStyle As New DataGridTextBoxColumn
myStyle.MappingName = "Emp_name"
myStyle.HeaderText = "Employee Name"
|
|
|
|
|
Since your SQL code is in code use As clause in SQL with [receipt no] and modify your code to use Receipt no as the field name
|
|
|
|
|
Hi... Am new to .net here. Hope am posting the question under the right category... My requirement is as follows:
I have a gridview which is visible with an empty row on page load. It has four columns of which the first column is a text box item template. The rest 3 are bound fields. Now, when I enter a valid data in the text box(for eg, an employee ID)and hit the enter key, the rest of the fields must be bound to the grid. All four columns are available in a table in the back end. I have used a datatable and made the gridview datasource as the datatable. Am using a stored procedure to bind the data.. Using SQL Server 2008(.Net 3.5 framework). Kindly help... Im totally blank right now...
|
|
|
|
|
Following code is useful to you.
void dataGrid _EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dgr = (DataGridView)sender;
if (dgr.CurrentCell.ColumnIndex == 2)
{
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
}
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(char.IsDigit(e.KeyChar)))
{
if (e.KeyChar == Keys.Enter)
{
e.Handled = true;
}
}
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
|
Hi sr159,
Please do not re-post the question.
You have already posted it here[^], and got resolution.
Please read guidelines[^] for better understanding of how to get answer and post question in this forum.
Hope you understand.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
hi sr159,
Why you have down voted me and removed your message?
Do not remove your message once you posted it, if it has
answers under it.
The question posted by sr159 is as follow
[Edit]
some changes made like form load and creating function and it is executing and also that is taking values from dump file but again not saving to database. please reply me
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace dump
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
restore_data("temple1");
}
catch (Exception ex)
{
Application.Exit();
}
}
public void restore_data(string database)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe");
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} &lt;{4}", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
}
}
[/Edit]
Hope you understand.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
how to restore mysql dump file to database using C#
i am using following code but not working, if u know anyone please reply me
public void restore_data(string temple1)
{
StreamReader file = new StreamReader("E:\\BackupMysql1\\temple.sql");
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} <(4)", "dfs", "sf#", "localhost", '"' + temple1 + '"', "E:\\BackupMysql1\\temple.sql");
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = false;
proc.Arguments = cmd;
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = file.ReadToEnd();
p.WaitForExit();
file.Close();
}
modified on Friday, July 16, 2010 3:18 AM
|
|
|
|
|
hi,
There isn't any option available to import mysql dump file directly to
sql server. Because the data exported by mysql as dump is not compatible
with sql server to restore at one go.
You need to use phpmyadmin or some other tool to export mysql database
(export as excel or some other format that is compatible in sql server),
instead of taking dump directly from command prompt.
And then try to restore it.
However, if you have to restore backup file of sql server into another
database (sql server to sql server) then it is absolutely possible in
C# using SQL SMO.
Find following link for the same.
http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html[^]
http://www.mssqltips.com/tip.asp?tip=1849[^]
And please use pre tag to format your code and mark your "Message Type" as "Question" not as "General".
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
we are using mysqlserver 2005 and sql yog for database management not sql server 2005
but the code which we are using is not working
|
|
|
|
|