How to detect if the Autoscrollposition value changes in the panel1?
For example,
textbox1 and textbox2.
which added in panel1. The autoscroll property is set to true.
I am only interested in detecting when the value of panel autoscrollposition changes.
The above for dynamic textboxes which are incremented.
Software in use: C#, Visual Studio 2005.
The Component required for it. is:
ListBox1
ListBox2
Panel
Button.
The Namespace for Class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
Here is the Complete Solution Code:
namespace detectpanelvalue
{
public partial class Form1 : Form
{
private Point tbpoint = new Point(10, 14);
private Point tbbpoint = new Point(300, 14);
private ArrayList arylst;
private ArrayList arylst1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Paint += new PaintEventHandler(panel1_Paint);
}
void panel1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Point pnlpt;
pnlpt = panel1.AutoScrollPosition;
if (tbpoint !=null || pnlpt != null )
{
pnlpt = tbpoint;
}
arylst1 = new ArrayList();
arylst1.Add(pnlpt);
}
private void runtime()
{
foreach (Point pt in arylst)
{
listBox1.Items.Add(pt);
}
foreach (Point ptt in arylst1)
{
listBox2.Items.Add(ptt);
}
}
private void button1_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.Location = tbpoint;
this.panel1.Controls.Add(tb);
tbpoint.Y += 30;
TextBox bb = new TextBox();
bb.Location = tbbpoint;
this.panel1.Controls.Add(bb);
tbbpoint.Y += 30;
arylst = new ArrayList();
arylst.Add(tbpoint);
runtime();
}
}
}
It is helpful for adjust the panel autoscrollposition.
Related
LastPickName is not empty but it kept picking the else statement... maybe I'm putting it in the wrong area?
I have a label text to output what's in LastPickName just to make sure it's not empty or empty.
using Plugin.Settings;
using Plugin.Settings.Abstractions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App424
{
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
private static ISettings AppSettings => CrossSettings.Current;
public static string LastPickValue
{
get => AppSettings.GetValueOrDefault(nameof(LastPickValue), string.Empty);
set => AppSettings.AddOrUpdateValue(nameof(LastPickValue), value);
}
public static string LastPickName
{
get => AppSettings.GetValueOrDefault(nameof(LastPickName), string.Empty);
set => AppSettings.AddOrUpdateValue(nameof(LastPickName), value);
}
public object LastPickname { get; private set; }
public MainPage()
{
InitializeComponent();
List<string> list = new List<string>();
list.Add("Right1");
list.Add("Right2");
list.Add("Right3");
list.Add("Right4");
//populate picker selection
drainlocationPicker1.ItemsSource = list;
//Set the default value
drainlocationPicker1.SelectedItem = LastPickValue;
nameEntry.Placeholder = LastPickName;
//names.Text = LastPickName;
nameLabel.Text = LastPickName;
if (LastPickName == null)
{
settingsButton.IsVisible = true;
nextButton.IsVisible = false;
}
else
{
nextButton.IsVisible = true;
settingsButton.IsVisible = false;
}
void Handle_Unfocused(object sender, Xamarin.Forms.FocusEventArgs e)
{
LastPickName = nameEntry.Text;
}
private void DrainlocationPicker1_SelectedIndexChanged(object sender, EventArgs e)
{
string nlocation1 = (string)drainlocationPicker1.SelectedItem;
LastPickValue = nlocation1;
}
}
}
}
LastPickName is empty it should show settingsButton if not show nextButton.
LastPickName is empty why is it not showing settingsButton?
if (LastPickName == "")
i thought null is empty but as Sami commented it's not.
I want to change the height of the bottom TabBar in my Xamarin app. Now I am doing this via ViewModel properties:
public partial class MainPage : TabbedPage
{
public int TabBarHeight
{
get { return _tabBarHeight; }
set { _tabBarHeight = value; OnPropertyChanged(); }
}
int _tabBarHeight = 200;
And a custom renderer for iOS:
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.Diagnostics;
using Ja.Enums;
using System.ComponentModel;
using CoreGraphics;
[assembly: ExportRenderer(typeof(TabbedPage), typeof(Ja.iOS.TabbedPageRenderer))]
namespace Ja.iOS
{
public class TabbedPageRenderer : TabbedRenderer
{
private MainPage _page;
public TabbedPageRenderer()
{
this.ViewControllerSelected += OnTabbarControllerItemSelected;
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
TabBar.Frame = new CGRect(TabBar.Frame.X, TabBar.Frame.Y + (TabBar.Frame.Height - _page.TabBarHeight), TabBar.Frame.Width, _page.TabBarHeight);
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
e.OldElement.PropertyChanged -= Current_PropertyChanged;
return;
}
if (e.NewElement != null)
{
_page = (MainPage)e.NewElement;
e.NewElement.PropertyChanged += Current_PropertyChanged;
}
}
void Current_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "FrameHeight")
ViewWillLayoutSubviews();
}
}
}
Is this an optimal way to be doing this? I seem to remember having a shared class. That class would contain the code that's in the first few lines of my main as bound elements.
Could anyone comment on this and perhaps suggest a better way of doing this.
Looks like something I would use a Custom Control for (which is what I think you mean with 'shared class').
First you create the class below in your PCL. A CustomTabbedPage, which inherits from TabbedPage but has one extra property: 'TabBarHeight'
public class CustomTabbedPage : TabbedPage {
public static readonly BindableProperty TabBarHeightProperty = BindableProperty.Create("TabBarHeight", typeof(int), typeof(TabbedPage), 0);
public int TabBarHeight {
get { return (int)GetValue(TabBarHeightProperty); }
set { SetValue(TabBarHeightProperty, value); }
}
}
Now edit your renderer to a renderer of the CustomTabbedPage. Then you can easily access the TabBarHeight property by using this.Element.TabBarHeight.
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.Diagnostics;
using Ja.Enums;
using System.ComponentModel;
using CoreGraphics;
[assembly: ExportRenderer(typeof(CustomTabbedPage), typeof(Ja.iOS.CustomTabbedPageRenderer))]
namespace Ja.iOS
{
public class CustomTabbedPageRenderer : TabbedRenderer
{
public TabbedPageRenderer()
{
this.ViewControllerSelected += OnTabbarControllerItemSelected;
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
TabBar.Frame = new CGRect(TabBar.Frame.X, TabBar.Frame.Y + (TabBar.Frame.Height - this.Element.TabBarHeight), TabBar.Frame.Width, this.Element.TabBarHeight);
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null) {
e.OldElement.PropertyChanged -= Element_PropertyChanged;
}
if (e.NewElement != null) {
e.NewElement.PropertyChanged += Element_PropertyChanged;
}
}
void Current_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "FrameHeight")
ViewWillLayoutSubviews();
}
}
}
There might be some syntax errors in there but you get the point.
Shoot if you have any questions.
Scenario: There is following controls in the form:
datagridview, textbox1, textbox2, button(save,edit,update,delete)
1.By clicking on save button, data should be updated into datagridview at run-time.
2.By selecting complete row and clicking on edit button, data should be retrieved into textboxes.
3.By clicking on Update button, that data should be updated.
4.By selecting a complete row, the row should be deleted.
This is my code.
I hope it will help you
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace LINQ_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
LINQtestDataContext dc = new LINQtestDataContext();
public void show_data()
{
dataGridView1.DataSource = (from t in dc.LinqTests
select t);
}
public void insert_data()
{
try
{
LinqTest tbl = new LinqTest
{
ID=Convert.ToInt32(textBox_id.Text),
Name=textBox_name.Text
};
dc.LinqTests.InsertOnSubmit(tbl);
dc.SubmitChanges();
MessageBox.Show("Data Inserted!!!");
show_data();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void update_data()
{
try
{
LinqTest tbl = dc.LinqTests.Single(x=>x.ID==Convert.ToInt32(textBox_id.Text));
tbl.Name = textBox_new_name.Text;
dc.SubmitChanges();
MessageBox.Show("Data Updated!!!");
show_data();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void delete_data()
{
try
{
LinqTest tbl = dc.LinqTests.Single(x => x.ID == Convert.ToInt32(textBox_id.Text));
dc.LinqTests.DeleteOnSubmit(tbl);
dc.SubmitChanges();
MessageBox.Show("Data Deleted!!!");
show_data();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
show_data();
}
private void button_insert_Click(object sender, EventArgs e)
{
insert_data();
}
private void button_update_Click(object sender, EventArgs e)
{
update_data();
}
private void button_delete_Click(object sender, EventArgs e)
{
delete_data();
}
}
}
I have a small app there is 3 seconds intro page, then the content page. When I push back button I go back to the intro screen, but I think I should go back to the system. How to do it?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ServiceModel.Syndication;
using System.Xml;
using Microsoft.Phone.Tasks;
namespace RSS {
public partial class FeedPage : PhoneApplicationPage {
public FeedPage() {
InitializeComponent();
this.Loaded += new RoutedEventHandler(PhonePage1_Loaded);
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {
clearBackStack();
base.OnNavigatedTo(e);
}
void clearBackStack() {
while (this.NavigationService.BackStack.Any()) {
this.NavigationService.RemoveBackEntry();
}
}
void PhonePage1_Loaded(object sender, RoutedEventArgs e) {
// clearBackStack();
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri("http://www.carmagazine.co.uk/Shared/Handlers/RssHandler.ashx?&N=190&Ns=P_Publication_Date|1&?"));
}
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {
SyndicationFeed feed;
try {
using (XmlReader reader = XmlReader.Create(e.Result)) {
feed = SyndicationFeed.Load(reader);
lista.ItemsSource = feed.Items;
}
} catch (WebException we) { MessageBox.Show("Internet connection is down.");}
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e) {
WebBrowserTask webBrowserTask = new WebBrowserTask();
String url = (String)((Button)sender).Tag;
webBrowserTask.Uri = new Uri(url);
webBrowserTask.Show();
}
}
}
You should clear the BackStack in the OnNavigateTo method of your content page
while (this.NavigationService.BackStack.Any())
{
this.NavigationService.RemoveBackEntry();
}
The following code is the best practice for the back button key press.
protected override void OnBackKeyPress(CancelEventArgs e)
{
while (NavigationService.CanGoBack)
NavigationService.RemoveBackEntry();
base.OnBackKeyPress(e);
}
This ensures that your application will exit and return to the main screen on pressing the BackKey.
i have problem in this code in the comment area "hang the form"
my program will hang there!!!! what is problem??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication28
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BackgroundWorker backgw = new BackgroundWorker();
private void button1_Click(object sender, EventArgs e)
{
backgw.DoWork += new DoWorkEventHandler(k_DoWork);
ParameterizedThreadStart start = new ParameterizedThreadStart(startthread);
System.Threading.Thread u;
int i = 0;
while (i < 100)
{
//u = new System.Threading.Thread(start);
//u.Start(i); //1.with thread way
backgw.RunWorkerAsync(i); //2.with backgw way
Thread.Sleep(1000);
lock (y)
{
Thread.Sleep(1000);
}
lock(h)
i++;
}
}
delegate void j(int h);
j b;
object h = new object();
object y = new object();
void startthread(object m)
{
Monitor.Enter(h);
Monitor.Enter(y);
p1((int)m);
Monitor.Exit(h);
}
void p1(int h)
{
b = delegate(int q)
{
label1.Text = string.Format("Step is :{0}", h.ToString());
};
Monitor.Exit(y);
label1.Invoke(b); //hang the form????
}
void k_DoWork(object sender, DoWorkEventArgs e)
{
Monitor.Enter(h);
Monitor.Enter(y);
p1((int)e.Argument);
Monitor.Exit(h);
}
}
}
Invoke waits for the function to return. The UI thread will be running the loop for a few minutes, the worker thread will be waiting for the UI thread to invoke and return.
Use BeginInvoke to put the task on the UI thread without blocking.