Friday, June 22, 2012

Myth Tick and Bookmark - HTML5

Pembacaan dan research ringkas tentang HTML5..
(rugi xresearch betul2 sebelum interview thun lepas..huuu)





"...'it' can only previously be done using javascript, now it focusing on browser..browser should and would be able to do all those thing"

sbg cth, sblm ni memainkan video hanya boleh dilakukan dengan bantuan player/plugin (eg flash player)..tp html5 membolehkan browser itu sendiri memainkan video tanpa perlu mendonwload/memerlukan plugin tambahan..






themythstoodstill: Lepas ni nak buat html, boleh cuba html5..even skrg browser xsupport html5 sepenuhnya, tp in the future..

http://html5test.com/

Tuesday, May 8, 2012

Myth Bookmark 2 : C# - Minimize WPF to System Tray in C#

Google Search: c#  WPF Minimize on Taskbar

The best solution found: http://ebbypeter.wordpress.com/2010/06/28/minimize-a-wpf-application-to-system-tray-in-c/

1. global variable for NotifyIcon

private System.Windows.Forms.NotifyIcon MyNotifyIcon;
2. initiate NotifyIcon. Declare/Initialize event to bring back App from taskbar
public MainWindow()
{
InitializeComponent();
MyNotifyIcon = new System.Windows.Forms.NotifyIcon();
MyNotifyIcon.Icon = new System.Drawing.Icon(
@"C:\Archive\Icon-Archive.ico");
MyNotifyIcon.MouseDoubleClick +=
new System.Windows.Forms.MouseEventHandler
(MyNotifyIcon_MouseDoubleClick);
}

3. Event/Button to minimize
private void btnQuit_Click(object sender, RoutedEventArgs e){   this.WindowState = WindowState.Minimized;}

4. Event bring back /restore App from taskbar
void MyNotifyIcon_MouseDoubleClick(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.WindowState = WindowState.Normal;

5. Balloon tips (mine not working. haven't fix yet [8/5/12])
private void Window_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{
this.ShowInTaskbar = false;
MyNotifyIcon.BalloonTipTitle = "Minimize Sucessful";
MyNotifyIcon.BalloonTipText = "Minimized the app ";
MyNotifyIcon.ShowBalloonTip(400);
MyNotifyIcon.Visible = true;
}
else if (this.WindowState == WindowState.Normal)
{
MyNotifyIcon.Visible = false;
this.ShowInTaskbar = true;
}
}

Thursday, January 26, 2012

Myth Bookmark 1 : C# - Get WPF Datagrid Selected Row Cell Value

Google : get wpf datagrid selected row cell value

Solution found : http://stackoverflow.com/questions/2148978/wpf-toolkit-datagrid-selectionchanged-getting-cell-value

private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid dataGrid = sender as DataGrid;
if (e.AddedItems!=null && e.AddedItems.Count>0)
{
    // find row for the first selected item
    DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]);
    if (row != null)
    {
        DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
        // find grid cell object for the cell with index 0
        DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;
        if (cell != null)
        {
            Console.WriteLine(((TextBlock)cell.Content).Text);
        }
    }
}
}
static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
    Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
    child = v as T;
    if (child == null) child = GetVisualChild<T>(v);
    if (child != null) break;
}
return child;
}

Monday, November 28, 2011

Myth Self Note 10: C# WPF - Update UI in other Thread


Problem:
1 - Error Message: "The calling thread cannot access this object because a different thread owns it"
2 - Can't add value or edit listbox while using thread

Search Key:
1 - listbox c# thread used cannot access

Solution:
Use "Dispatcher.Invoke"

'Myth' Example:
1- this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
{
//do something here
}));

Screenshot Example:
2 - call the function from the running thread
"Thread t = new Thread(startScan);
t.Start();"

private void startScan()
{
bla bla bla
ProgressChanged(filesPath);
bla bla bla
}

Help Link:

Thursday, November 10, 2011

Myth Self Note 9: C# WPF - Recursive Loop

Notes:
using recursive loop..

the different is, using
DirectoryInfo.GetFiles()
method, it will search all files in the particular directory then store in an array..then we will loop the array and scan/do function on each item in the array...

the purpose i'm doing the coding manually (recursive loop) is because everytime i encounter a file, i will scan/do some function on it...then store it in the array...(different from GetFiles)

here's my coding..

declare array mypath to store choosen path to be scan for files
private string[] mypath;

store all choosen path in the array
mypath = File.ReadAllLines("scanpath.scn");

this will call the function to search all files in the directory and subdirectory
searchFile();

the function searchFile, loop root directory that i choose in scanpath file just now.
private void searchFile()
{
for (int i = 0; i < mypath.Length ; i++)
{
DirectoryInfo myRoot = new DirectoryInfo(mypath[i]);
string[] myDir = Directory.GetDirectories(mypath[i]);

showFile(myRoot);
recursiveLoop(myDir);

}
}


the function showFile, show/add the list of files in the directory into a listview
private void showFile(DirectoryInfo myDir)
{
string myPath = "";
string myPath2 = "";

foreach (FileInfo file in myDir.GetFiles())
{
myPath = file.ToString();
myPath2 = myDir + "\\" + myPath;

lstScan.Items.Add(myPath2);
string result = doFunction(myPath2);
if (!result.Equals(string.Empty))
{
addIntoListView(myPath, result);
}
}
}

the function recursiveLoop, which will loop and search files in each subdirectory in the directory..and also subdirectory in the subdirectory..untill all files in the root directory and all its subdirectory'subdirectory and so on..
private void recursiveLoop(string[] subdir)
{
foreach (string s in subdir)
{
try
{

DirectoryInfo mySub = new DirectoryInfo(s);
string myPath = "";
string myPath2 = "";

foreach (FileInfo file in mySub.GetFiles())
{
myPath = file.ToString();
myPath2 = mySub + "\\" + myPath;

lstScan.Items.Add(myPath2);
string result = doFunction(myPath2);
if (!result.Equals(string.Empty))
{
addIntoListView(myPath, result);
}
}

string[] myDir = Directory.GetDirectories(s);
recursiveLoop(myDir);
}
catch (Exception c)
{
// Console.WriteLine("Error: " + c.Message);
}
}
}