Google
 

Sunday, July 22, 2007

Moving a form without a title bar

How to make a form without a title bar movable?

This is a common request in programming forums, and here is a simple solution that depends on handling mouse down and mouse move events:


public partial class Form1 : Form
{
int m_PrevX;
int m_PrevY;

public Form1()
{
InitializeComponent();
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;

Left = Left + (e.X - m_PrevX);
Top = Top + (e.Y - m_PrevY);

}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button!=MouseButtons.Left)
return;

m_PrevX = e.X;
m_PrevY = e.Y;
}

Sunday, July 15, 2007

MS SQL Server Views: Order By

If you create a view in SQL Server 2005 management studio and add an order by clause, run the query, the order by seems to take effect.
But when you reference the view in a simple query (with no order by) you find that the returned results are not as expected, records are not ordered..
check the definition of the created view :

sp_helptext view_name

you find that the management studio added a TOP clause to the view.
reviewing SQL Server Books Online:

SQL Server 2000:
The query defining the view cannot include the ORDER BY, COMPUTE, or COMPUTE BY clauses or the INTO keyword.

SQL Server 2005:
The SELECT clauses in a view definition cannot include the following:
.
.
An ORDER BY clause, unless there is also a TOP clause in the select list of the SELECT statement

This makes extreme sense to me, as views represent logical tables, so just like tables, the order in which you get data should not be assumed, unless explicitly requested using an order by in the query.

Saturday, July 14, 2007

Posting dynamic data to a popup page

It's a common need to pass some JavaScript dynamically formatted data to a pop up page, this can be easy as you just need to append data to the URL of the pop up and open it using window.open() or simply by setting the src property of an anchor element, this is a get request.

But if the data is too big to be put in the query string (2kb+), or if you want to make it harder for the user to see and modify the passed parameters, you'll need to post this data.

this JavaScript function makes the job, I post the string ("real long data").

function PostToPopup()
{
window.open("about:blank","popup",null,null);

var hdn= document.createElement("Input");
hdn.type="hidden";
hdn.name="popupdata";

var frm= document.createElement("Form");

frm.target="popup";
frm.method="POST";
frm.action="popup.aspx";

document.body.appendChild(frm);
frm.appendChild(hdn);

hdn.value="real long data";

frm.submit();
}


You can read this value in the popup from the request..this is an ASP.NET example:
Response.Write(Request.Form["popupdata"]);

Sunday, July 1, 2007

I passed this semester with 3 'A's

I my computer science diploma study at aast (Arab Academy for and technology and maritime transport), I passed the summer semester with grade A for the three courses I studied.
I studied Software Engineering, Database management systems ,and web programming.
The most one that I'm happy with is the web programming course. I made a Java application which is an online image album and editor.
What I liked about this project is that it utilized the client to make all the image effects (using a Java applet). The applet communicates with the server to get the image and to save it by calling a servlet. new thing that I've learned.
I wish to share the code of this project and publish it, maybe as an article.