browse by category or date

I always consider blogging as a mean to improve yourself. By sharing your knowledge, you actually become more knowledgable on that subject you are writing about. To create an article, usually it starts with what you know. Moving to the next paragraphs you realize that you forgot a detail about something, you then googled, read a book and find answer to your own question. Thus, now you know more about the subject you writing.

I was highly inspired by these advises so i decided to record them in a single post which we can refer again and again

OK, It’s time to relax and let the points sink down into our brain. Hopefully it will be useful and affect us in may good ways.

GD Star Rating
loading...

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

JavaScript has become more and more important part of Web Application. Often, it does a crucial role such as doing the data verification check on the client side. Quite often also, we use JavaScript to limit the behavior of a field to suit our need. For example, making a textbox to only accept numbers.

But all this fancy ideas will not work if the JavaScript is disabled. To check wheter your user have their Javascript enabled in their environment, add the following snippets into your form:

<head>
<script type="text/javascript">

function checkJavascript()
{ 
    var obj = document.getElementById('javascriptCheck');
    obj.value ="1";
} 

</script>
</head>
<body onload="checkJavascript();">
   <form><input type="hidden" id="javascriptCheck" name="javascriptCheck" value="0" />
       ....
       <!-- put the remaining form in inputs here -->
      ....
   </form>
</body>

 

On the server you will need to check is the ‘javascriptCheck’ variable’s value is ‘1’. If it is, it means Javascript is enabled.

GD Star Rating
loading...

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

There are days when we actually need to get the full path location of a file. A quick example would be when you are adding entries into your Book Collector application. After downloads all information about the particular book you are adding, you are then adding the path of the e-Book into the ‘eBook Textbox’ entry. To fill up the entry, you can either browse for the file, or quickly copy and paste the full path location of the file. Usually the latter option is the fastest. Normally, you will do it in the following sequence:

  1. Open ‘Explorer
  2. Navigate the the folder, copy the folder name from address bar
  3. Return back to Book Collector, paste the folder name at the textbox
  4. Return again to Explorer, select the file, press F2/single-click, then copy the filename.
  5. Finally return to Book Collector to paste the filename.

This will become tedious and tiring once you have tens or hundreds entries to key in. So I came up with this solution. The logic of the application will be:

  1. Create a small, transparent floating box which is movable with mouse drag
  2. You can drag and drop a file to this floating box
  3. The full path of that file is copied to the Clipboard
  4. You can go back to Book Collector (or any other use) and paste the full path using Ctrl+V / right-click+paste

Lets tackle the requirement one by one. To create a small, transparent and floating box you need to set the following property:

  • AllowDrop: Change it into True to allow us drag-and-drop object to this Windows Form
  • BackColor: Change it into something cool (which is other than gray)
  • ControlBox: You only need the box. Set it into False
  • FormBorderStyle: Change it to anything but Sizeable.
  • Locked: Set it into True.
  • MaximizeBox: Set it into False
  • MinimizeBox: Set it into False
  • Opacity: This property regulate how transparent is your Windows Form.0% is completely invisible. 100% is not transparent at all. Set the value into around 50%
  • ShowIcon: Set it into False
  • ShowInTaskbar: Set it into False
  • TopMost: Set it into True

Finally modify the constructor to automatically set the size

public Form1()
{ 
	InitializeComponent();
    this.SuspendLayout();
    this.Size = new Size(35, 35);
    this.ResumeLayout();
} 

To allow the window to be moved by dragging, you need to declare class-wide variable and create Event handlers

private bool isMouseDown = false; // to record whether window on dragging mode 
private int oldX; //x-axis position when dragging start 
private int oldY; //y-axis position when dragging start 

// handle MouseDown Event
private void mouseDown(object sender, MouseEventArgs e) 
{
	oldX = e.X; 
    oldY = e.Y;
    isMouseDown = true; 
}

// handle MouseMove Event 
private void mouseMove(object sender, MouseEventArgs e)
{
	if (isMouseDown)
		this.Location = new Point(e.X+this.Location.X-oldX, e.Y+this.Location.Y-oldY);
}

// handle MouseUp Event 
private void mouseUp(object sender, MouseEventArgs e)
{
	if (isMouseDown)
		isMouseDown = false;
}

// handle Keypress Event 
// To close the program when user press 'q' 
private void Keypressed(object sender, KeyPressEventArgs e)
{
	if (e.KeyChar == 'q')
		this.Close();
}

The next step is to take care when a user Drop an object into the form

private void FmDragOver(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(DataFormats.FileDrop) 
	|| e.Data.GetDataPresent(DataFormats.StringFormat))
	{
		if ((e.AllowedEffect & DragDropEffects.Move) != 0)
			e.Effect = DragDropEffects.Move;
		if (((e.AllowedEffect & DragDropEffects.Copy) != 0) 
		&& ((e.KeyState & 0x08) != 0))
			e.Effect = DragDropEffects.Copy;
	}
}
private void FmDragDrop(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(DataFormats.FileDrop))
	{
		string[] astr = (string[])e.Data.GetData(DataFormats.FileDrop);
		Clipboard.SetText(astr[0]);
	}
}

Download the project here:

This solution has helped me save many minutes spend browsing, copy-pasting file’s full path. I hope it help you too.

Reference:
MSDN
GD Star Rating
loading...

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.