Software development podcasts are a great way to keep up with the always changing tech industry.
.NET Rocks Podcast is my favorite podcast about software development and not because I work with .NET but overall quality of the show is presented. The show is hosted by Carl Franklin and Richard Campbell; where they conducts a weekly interview to industry experts such as Scott Guthrie and Billy Hollis.
To listen:
http://www.netcastia.com/dotNETRocks
or
http://www.dotnetrocks.com/
Thursday, May 19, 2011
Tuesday, May 17, 2011
Remove read only attribute of a file in C#
To manipulate file attribute in C# we can use the System.IO.FileInfo class.
So, let’s say that we have a “Read Only” file located at C:\temp\test.jpg what we need to modify; however, we need to remove the “Read Only” attribute before we can continue.
Here is how to do it:
FileInfo file = new FileInfo(@"C:\temp\test.jpg");
file.Attributes = file.Attributes & ~FileAttributes.ReadOnly;
The above sample uses the bitwise operator in order to remove the “Read Only” attribute while ensuring that all other attributes that the file may have are not also removed during this operation.
Saturday, May 14, 2011
Create Thumbnails with the C# Image Class
Here is a quick tutorial on how to create thumbnail images using the System.Image class.
First let’s create a Windows Form project.
Then add a Button control and a PictureBox control.
Now add a click event to the Button control.
First let’s create a Windows Form project.
Then add a Button control and a PictureBox control.
Now add a click event to the Button control.
private void button1_Click(object sender, EventArgs e)
{
Image img = Image.FromFile(@"C:\folder\sampleImage.jpg");
this.pictureBox1.Image = img.GetThumbnailImage(120, 120,
new Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
}
public bool ThumbnailCallback()
{
return true;
}
First, we need an empty method (ThumbnailCallback) to pass to the GetThumbnailImageAbort delegate. Then, we simply create an Image object (I am using the FromFile method referencing a local file). Finally, assign the image to the PictureBox control to display it.
Let's run it:
Now click "Load Image":
Sunday, May 8, 2011
JavaScript rollover images
Here is a quick tutorial to show you a function to make JavaScript rollovers.
The function
var devc = {
rollover: function (id, img1, img2) {
this.addEvent(id, 'mouseover', function () {
$(id).src = img2;
});
this.addEvent(id, 'mouseout', function () {
$(id).src = img1;
});
},
addEvent: function (id, _event, _function) {
_object = $(id);
if (_object.addEventListener) {
_object.addEventListener(_event, _function, false);
} else if (_object.attachEvent) {
if (_event.length > 2) {
if (_event.substring(0, 2) != "on") {
_event = 'on' + _event;
}
}
_object.attachEvent(_event, _function);
}
}
};
I added the addEvent function from our previous post for convenience; however, you can see the original post from the link in the resource section of this post.
The rollover function simply adds two functions to the onmouseover and onmouseout events. The JavaScript on mouse over assigns image 2 to the image object and onmouseout adds image 1 to the image object.
Usage:
JavaScript
window.onload = function () {
devc.rollover('roll', 'star.png', 'starover.png');
};
HTML
<img id='roll' src="star.png" />
Monday, May 2, 2011
Using JavaScript to Change Opacity of an Object
I will show you how to change the opacity value of an object using JavaScript. I will create a function that can be use in conjunction with the animation function posted earlier (see resources below).
The function is simple
var developercaster = {
opacity: function (id, opacity) {
var o = $(id).style;
o.opacity = (opacity / 100);
o.MozOpacity = (opacity / 100);
o.KhtmlOpacity = (opacity / 100);
o.filter = "alpha(opacity=" + opacity + ")";
}
}
See usage example:
Set opacity to 0 on object id = ‘i’
developercaster.opacity(’i’, 0);
However, the function by itself is not as useful but when combined with our previously posted animation function it can be a neat tool to have. So, I will add two of our extra functions to this example:
var developercaster = {
opacity: function (id, opacity) {
var o = $(id).style;
o.opacity = (opacity / 100);
o.MozOpacity = (opacity / 100);
o.KhtmlOpacity = (opacity / 100);
o.filter = "alpha(opacity=" + opacity + ")";
},
animate: function (params) {
var speed = Math.round(params.speed / 1000);
var timer = 0;
if (params.start > params.end) {
for (var i = params.start; i >= params.end; i--) {
(function (i, _f, speed, timer) {
setTimeout(function () { _f(i); }, (timer * speed));
})(i, params.func, speed, timer);
timer++;
}
} else if (params.start < params.end) {
for (var index = params.start; index <= params.end; index++) {
(function (i, _f, speed, timer) {
setTimeout(function () { _f(i); }, (timer * speed));
})(index, params.func, speed, timer);
timer++;
}
}
//Callback
if (typeof (params.callback) != 'undefined') {
if ((typeof (params.callback) == 'function')) {
window.setTimeout(function () {
params.callback(); //Execute callback
}, (speed * timer));
}
}
},
addEvent: function (id, _event, _function) {
_object = $(id);
if (_object.addEventListener) {
_object.addEventListener(_event, _function, false);
} else if (_object.attachEvent) {
if (_event.length > 2) {
if (_event.substring(0, 2) != "on") {
_event = 'on' + _event;
}
}
_object.attachEvent(_event, _function);
}
}
};
Usage example:
JavaScript
window.onload = function () {
developercaster.opacity('i', 0);
developercaster.addEvent('show', 'click', function () {
developercaster.animate({
speed: 5000,
start: 0,
end: 100,
func: function (i) {
developercaster.opacity('i', i);
}
});
});
developercaster.addEvent('hide', 'click', function () {
developercaster.animate({
speed: 5000,
start:100,
end: 0,
func: function (i) {
developercaster.opacity('i', i);
}
});
});
};
HTML
<input name="show" type="button" value="Show Object" />
<input name="hide" type="button" value="Hide Object" />
<div id="i" style="width:300px; height:200px; border:1px solid #333333;background-color:Red">
Box
</div>
Resources:
Dollar function source code: here
AddEvent original post: here
Animate function previous post: here
Subscribe to:
Posts (Atom)