I am trying to get rid of the tensile drag for scrolling a Container with a BoxY Layout.
Code:
f.setScrollable(false);
appendExit(f);
String form_uuid = "";
Container tlist = new Container(new BoxLayout(BoxLayout.Y_AXIS));
tlist.setScrollableY(false);
tlist.setTensileDragEnabled(false);
Container tocCntn = new Container(new BoxLayout(BoxLayout.Y_AXIS));
tlist.setUIID("toc");
BorderLayout bl = new BorderLayout();
bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
Container tocH = new Container(bl);
Label lic = new Label(AppState.res.getImage("Menu_Icon.png"));
lic.setUIID("Container");
lic.getStyle().setMargin(Component.LEFT, 10);
tocH.addComponent(BorderLayout.WEST, lic);
Label l_h = new Label("Contents");
l_h.setUIID("typelabel");
tocH.addComponent(BorderLayout.CENTER, l_h);
tlist.addComponent(tocH);
TopicParser parser = new TopicParser();
switch (AppState.topic_type) {
case 1:
AppState.typelabel = "Listening Skills";
form_uuid = "lbg";
AppState.icon = AppState.res.getImage("licon.png");
brandface = AppState.res.getImage("list_girl.png");
AppState.current_topics = parser.parse(AppState.l_topics);
tocH.setUIID("ltoc");
break;
case 2:
AppState.typelabel = "Speaking Skills";
form_uuid = "rbg";
brandface = AppState.res.getImage("speak_girl.png");
AppState.icon = AppState.res.getImage("sicon.png");
AppState.current_topics = parser.parse(AppState.s_topics);
tocH.setUIID("stoc");
break;
case 3:
AppState.typelabel = "Reading Skills";
form_uuid = "rbg";
AppState.icon = AppState.res.getImage("ricon.png");
brandface = AppState.res.getImage("reading_boy.png");
AppState.current_topics = parser.parse(AppState.r_topics);
tocH.setUIID("rtoc");
break;
case 4:
AppState.typelabel = "Writing Skills";
form_uuid = "rbg";
brandface = AppState.res.getImage("writing_girl.png");
AppState.icon = AppState.res.getImage("wicon.png");
AppState.current_topics = parser.parse(AppState.w_topics);
tocH.setUIID("wtoc");
break;
}
int i = 0;
for (final Topic topic : AppState.current_topics) {
i++;
Container topicC = new Container(new BoxLayout(BoxLayout.Y_AXIS));
//topicC.setUIID("wbg");
if (topic.getTopic_name().trim().equals("")) {
Label l = new Label(" ");
l.setUIID("toclbl");
topicC.addComponent(l);
} else {
Button topicB = new Button(i + ". " + topic.getTopic_name());
topicB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
AppState.current_topic = topic;
showForm("player", null);
}
});
topicB.setUIID("toclbl");
topicC.addComponent(topicB);
}
tocCntn.addComponent(topicC);
}
tocCntn.setScrollableY(true);
tocCntn.setScrollVisible(false);
tocCntn.setTensileDragEnabled(false);
tlist.addComponent(tocCntn);
f.addComponent(BorderLayout.CENTER, tlist);
findTypename(f).setText(AppState.typelabel);
findTypeiconimg(f).setIcon(AppState.icon);
f.setGlassPane(new Painter() {
public void paint(Graphics g, Rectangle rect) {
g.drawImage(brandface, f.getLayoutWidth()-brandface.getWidth(), f.getLayoutHeight()-brandface.getHeight()-findTopicFooter(f).getLayoutHeight());
}
});
However it doesnt seem to work.
Is there any other way to achieve this ?
Is there a way to change the color of the scroll bar
setTensileDragEnabled should do the trick, I assume you are seeing the tensile drag of the Form itself rather then your tocCntn Container.
Try this:
Form f = new Form();
f.setLayout(new BorderLayout());
f.setScrollable(false);
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnt.setScrollableY(true);
cnt.setTensileDragEnabled(false);
//add Components to the cnt Container
...
f.addComponent(BorderLayout.CENTER, cnt);
f.show();
UIManager.getInstance().getLookAndFeel().setDefaultTensileDrag(false);
did the trick
Related
I get the following error on a Zebra tablet t55 when running my app:
Unhandled exception at 0x00007FFEA4A22D45 (Windows.UI.Xaml.dll) in PerfectDelivery.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
It happens after I load all my sqlite database and run the app the first time. After the crash I start the app back up again and it runs fine. The offending Combobox is here:
private void InitProducts()
{
StpProducts.Children.Clear();
_lstItemsInMultipleCrates = new List<int>();
Invoice deliveryDetails = new Invoice(((App)Application.Current).OrderId);
ItemsInCrate = new List<InvoiceItem>();
if (_selectedCrate != null)
{
btnFinishCrate.Visibility = Visibility.Visible;
foreach (InvoiceItem i in deliveryDetails.InvoiceItems.Where(
x => x.CrateNumber.CrateId == _selectedCrate))
{
ItemsInCrate.Add(i);
GridProducts = new Grid();
GridProducts.Height = 35;
GridProducts.Width = 600;
GridProducts.HorizontalAlignment = HorizontalAlignment.Left;
ColumnDefinition cdProductName = new ColumnDefinition();
cdProductName.Width = new GridLength(170, GridUnitType.Star);
ColumnDefinition cdQty = new ColumnDefinition();
cdQty.Width = new GridLength(45, GridUnitType.Star);
ColumnDefinition cdUnits = new ColumnDefinition();
cdUnits.Width = new GridLength(60, GridUnitType.Star);
ColumnDefinition cdChecked = new ColumnDefinition();
cdChecked.Width = new GridLength(30, GridUnitType.Star);
ColumnDefinition cdDropdown = new ColumnDefinition();
cdDropdown.Width = new GridLength(80, GridUnitType.Star);
ColumnDefinition cdFiller = new ColumnDefinition();
cdFiller.Width = new GridLength(1, GridUnitType.Star);
RowDefinition row = new RowDefinition();
row.Height = new GridLength(35, GridUnitType.Star);
GridProducts.ColumnDefinitions.Add(cdProductName);
GridProducts.ColumnDefinitions.Add(cdQty);
GridProducts.ColumnDefinitions.Add(cdUnits);
GridProducts.ColumnDefinitions.Add(cdChecked);
GridProducts.ColumnDefinitions.Add(cdDropdown);
TextBlock txbOrderDetailPickedId = new TextBlock { Name = "ODPID" };
txbOrderDetailPickedId.Text = i.OrderDetailPickedId.ToString("G");
txbOrderDetailPickedId.Visibility = Visibility.Collapsed;
TextBlock txbOriginalQty = new TextBlock { Name = "OQ" };
txbOriginalQty.Text = i.Quantity.ToString("N");
txbOriginalQty.Visibility = Visibility.Collapsed;
List<long?> lstCrateCount = new List<long?>();
foreach (InvoiceItem crateCount in deliveryDetails.InvoiceItems.Where(x => x.CrateNumber.OrderDetailPickedId == i.OrderDetailPickedId))
{
lstCrateCount.Add(crateCount.CrateNumber.CrateId);
}// return count of crates for item. If > 1 display crate number(s)
TextBlock txbProductName = new TextBlock();
TextBox txbQuantity = new TextBox();
txbQuantity.Text = i.Quantity.ToString("N");
txbQuantity.Height = 35;
InputScope scope = new InputScope();
InputScopeName scopeName = new InputScopeName { NameValue = InputScopeNameValue.Number };
scope.Names.Add(scopeName);
txbQuantity.InputScope = scope;
TextBlock txbUnits = new TextBlock();
txbUnits.Text = i.PackDescription;
txbUnits.HorizontalTextAlignment = TextAlignment.Center;
txbUnits.VerticalAlignment = VerticalAlignment.Center;
CheckBox chkChecked = new CheckBox();
---> CmbDiscrepancies = new ComboBox{ SelectedIndex = -1};
if (CmbDiscrepancies?.Items != null)
{
CmbDiscrepancies.Items.Add("Correct");
CmbDiscrepancies.Items.Add("Damaged");
CmbDiscrepancies.Items.Add("Missing");
CmbDiscrepancies.Items.Add("Wrong Item");
CmbDiscrepancies.Items.Add("Out of Stock");
CmbDiscrepancies.Items.Add("Incorrect Amt");
}
CmbDiscrepancies.SelectedIndex = 0;
CmbDiscrepancies.VerticalAlignment = VerticalAlignment.Center;*
if (lstCrateCount.Count == 1)
{
txbProductName.Text = i.ProductName;
}
else if (!Crate.ItemInMultipleCrates(i.OrderDetailPickedId))
{
_lstItemsInMultipleCrates.Add(i.OrderDetailPickedId);
txbProductName.TextWrapping = TextWrapping.Wrap;
txbProductName.Text = i.ProductName + "\r\n" + "(";
int count = 0;
foreach (long? crate in lstCrateCount)
{
count++;
txbProductName.Text += count != lstCrateCount.Count ? crate + ", " : crate + ")\r\nQty is the total in all crates listed above.";
}
GridProducts.Height = 50 * (lstCrateCount.Count * .66);
row.Height = new GridLength(GridProducts.Height, GridUnitType.Pixel);
}
if (Crate.ItemInMultipleCrates(i.OrderDetailPickedId))
{
txbProductName.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
CmbDiscrepancies.IsEnabled = false;
txbQuantity.IsEnabled = false;
if (_lstItemsInMultipleCrates.Count > 0)
GridProducts.Height = 35 * (_lstItemsInMultipleCrates.Count * 1.32);
else
{
GridProducts.Height = 35 * 1.32;
}
row.Height = new GridLength(GridProducts.Height, GridUnitType.Pixel);
txbProductName.Text = i.ProductName + "\r\n" + "(Item is in multiple crates)";
chkChecked.IsChecked = true;
chkChecked.IsEnabled = false;
}
GridProducts.Children.Add(txbOriginalQty);
GridProducts.Children.Add(txbOrderDetailPickedId);
GridProducts.Children.Add(txbProductName);
GridProducts.Children.Add(txbQuantity);
GridProducts.Children.Add(txbUnits);
GridProducts.Children.Add(chkChecked);
GridProducts.Children.Add(CmbDiscrepancies);
Grid.SetColumn(txbProductName, 0);
Grid.SetColumn(txbQuantity, 1);
Grid.SetColumn(txbUnits, 2);
Grid.SetColumn(chkChecked, 3);
Grid.SetColumn(CmbDiscrepancies, 4);
Grid.SetRow(txbProductName, 0);
Grid.SetRow(txbQuantity, 0);
Grid.SetRow(txbUnits, 0);
Grid.SetRow(chkChecked, 0);
Grid.SetRow(CmbDiscrepancies, 0);
GridProducts.RowDefinitions.Add(row);
StpProducts.Children.Add(GridProducts);
}
}
The XAML is
<ScrollViewer x:Name="ScvProducts" HorizontalAlignment="Left" Height="354" Margin="375,146,0,0" VerticalAlignment="Top" Width="638" BorderBrush="#FF1B933C" BorderThickness="2" >
<StackPanel x:Name="StpProducts" MinHeight="450" Width="612" HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Vertical" Height="995" >
<Grid x:Name="GridProducts">
<ComboBox x:Name="CmbDiscrepancies" Visibility></ComboBox>
</Grid>
</StackPanel>
</ScrollViewer>
Upgrading from Windows 10 1709 to 1803 fixed the existing code. I also got rid of the stack panel and add the row definitions dynamically which seems to have addressed the 1709 version.
I am implementing drop-drown feature in my app. Its implemented using container with list of elements in it.
Suppose the drop down list has following items aa1, aa2, aa3, aa4 aa5 and so on. And if i search as 'aa' it displays items starting from 'aa', if I select aa5 from list, it takes aa1 and displays that. But whereas if I scroll the items and select its working fine. This problem occurring only on iOS device working perfectly fine on simulator.
the first picture depicts how drop down looks like, in second picture if I search 'ee', it gives list of items starting with 'ee'. If I select 'ee5', it sets to ee1 as shown in picture 3. Problem only on device. Any workaround for this?
So, please let me know whats the issue with this.
Thanks
[![enter image description here][1]][1]
private CustomList itemList;
class CustomList extends List {
int startYPos = -1;
long lastDiff = 0;
Timer t = null;
int draggingState = 0;
public CustomList() {
this.setTensileDragEnabled(false);
}
}
private class ButtonListener implements ActionListener {
public void actionPerformed(final ActionEvent evt) {
final Runnable rn = new Runnable() {
public void run() {
// Create and show a dialog to allow users to make a selection.
final UiBuilder uib = dm.UiBuilder();
dialog = (Dialog) uib.createContainer(DESIGNER_NAME_DIALOG_COMBOBOX_CONTAINER);
GenericSpinner itemSpinner = (GenericSpinner) uib.findByName(DESIGNER_NAME_DIALOG_COMBOBOX_GENERIC_SPINNER, dialog);
itemSpinner.setPreferredW(Display.getInstance().getDisplayWidth() * 4 / 5);
//remove from parent and replace with a linear list
Container parent = itemSpinner.getParent();
parent.removeComponent(itemSpinner);
// Add the searchable text field box
final TextField tf = (TextField)uib.findByName("Search", dialog);
tf.addDataChangedListener(new DataChangedListener() {
#Override
public void dataChanged(int type, int index) {
Object[] items = model.getFilteredItems(tf.getText());
itemList.setModel(new DefaultListModel(items));
}
});
itemList = new CustomList();
itemList.getAllStyles().setBgTransparency(0);
itemList.setItemGap(0);
parent.addComponent(BorderLayout.CENTER, itemList);
final String[] items = model.getItems();
itemList.setModel(new DefaultListModel(items));
itemList.getStyle().setMargin(10, 10, 10, 10);
itemList.setFireOnClick(true);
itemList.setLongPointerPressActionEnabled(false);
ActionListener list = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (model.isUserEditable() && model.getItemCount() > 0) {
int i = itemList.getSelectedIndex();
if (i > items.length - 1) {
return;
}
itemList.getModel().setSelectedIndex(i);
model.onUserDataEntered((String) itemList.getModel().getItemAt(i));
String textToDisplay = (String) itemList.getModel().getItemAt(i);
button.setText(textToDisplay);
}
dialog.dispose();
}
};
itemList.addActionListener(list);
CommonTransitions tran = CommonTransitions.createEmpty();
dialog.setTransitionInAnimator(tran);
dialog.setTransitionOutAnimator(tran);
itemList.setRenderer(new ListRenderer());
//related to dialog to show list of items
//how much space do we really need???
if (cellHeight == 0) {
int dip = Display.getInstance().convertToPixels(1);
int siz = 2;
if (Display.getInstance().isTablet()) {
siz = 4;
}
siz *= 2;
cellHeight = siz * dip;
}
int heightRequired = cellHeight * (items.length + 8);
//is this too much for the screen - we will use 3/4 of the screen height max
int availableHeight = Display.getInstance().getDisplayHeight() * 3;
availableHeight /= 4;
if (heightRequired > availableHeight) {
int topPos = Display.getInstance().getDisplayHeight() / 8;
int bottomPos = topPos + availableHeight;
dialog.show(topPos, topPos, 40, 40);
}
else {
int topPos = (Display.getInstance().getDisplayHeight() - heightRequired) / 2;
int bottomPos = topPos + heightRequired;
dialog.show(topPos, topPos, 40, 40);
}
}
};
}
}
//new code using Multibutton implementation
final String[] listItems = model.getItems();
Display.getInstance().callSerially(() ->{
multiButton= new MultiButton();
multiButton.setTextLine1(s);
dialog.add(multiButton);
multiButton.addActionListener(e -> Log.p("you picked " + multiButton.getSelectCommandText(), Log.ERROR));
}
dialog.revalidate();
});
I would recommend using a Container and simple layout search as demonstrated by code such as this. The code below was taken from the Toolbar javadoc:
Image duke = null;
try {
duke = Image.createImage("/duke.png");
} catch(IOException err) {
Log.e(err);
}
int fiveMM = Display.getInstance().convertToPixels(5);
final Image finalDuke = duke.scaledWidth(fiveMM);
Toolbar.setGlobalToolbar(true);
Form hi = new Form("Search", BoxLayout.y());
hi.add(new InfiniteProgress());
Display.getInstance().scheduleBackgroundTask(()-> {
// this will take a while...
Contact[] cnts = Display.getInstance().getAllContacts(true, true, true, true, false, false);
Display.getInstance().callSerially(() -> {
hi.removeAll();
for(Contact c : cnts) {
MultiButton m = new MultiButton();
m.setTextLine1(c.getDisplayName());
m.setTextLine2(c.getPrimaryPhoneNumber());
Image pic = c.getPhoto();
if(pic != null) {
m.setIcon(fill(pic, finalDuke.getWidth(), finalDuke.getHeight()));
} else {
m.setIcon(finalDuke);
}
hi.add(m);
}
hi.revalidate();
});
});
hi.getToolbar().addSearchCommand(e -> {
String text = (String)e.getSource();
if(text == null || text.length() == 0) {
// clear search
for(Component cmp : hi.getContentPane()) {
cmp.setHidden(false);
cmp.setVisible(true);
}
hi.getContentPane().animateLayout(150);
} else {
text = text.toLowerCase();
for(Component cmp : hi.getContentPane()) {
MultiButton mb = (MultiButton)cmp;
String line1 = mb.getTextLine1();
String line2 = mb.getTextLine2();
boolean show = line1 != null && line1.toLowerCase().indexOf(text) > -1 ||
line2 != null && line2.toLowerCase().indexOf(text) > -1;
mb.setHidden(!show);
mb.setVisible(show);
}
hi.getContentPane().animateLayout(150);
}
}, 4);
hi.show();
Does anyone know why these controls are not shown on the form? If I add the controls with the same properties via design everything works just fine but if I use the same code from the designer in the form constructor with only other names nothing works.
private void CreatePlayingTab()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
//
// bunifuCustomLabel_Titel
//
BunifuCustomLabel bunifuCustomLabel_Titel = new BunifuCustomLabel();
bunifuCustomLabel_Titel.AutoSize = true;
bunifuCustomLabel_Titel.Font = new Font("Century Gothic", 11.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
bunifuCustomLabel_Titel.ForeColor = Color.FromArgb(224, 224, 224);
bunifuCustomLabel_Titel.Location = new Point(19, 30);
bunifuCustomLabel_Titel.Name = "bunifuCustomLabel_Titel";
bunifuCustomLabel_Titel.Size = new Size(153, 18);
bunifuCustomLabel_Titel.Text = "#001 Wer ist Naruto?";
//
// bunifuCustomLabel_Interpret
//
BunifuCustomLabel bunifuCustomLabel_Interpret = new BunifuCustomLabel();
bunifuCustomLabel_Interpret.AutoSize = true;
bunifuCustomLabel_Interpret.Font = new Font("Century Gothic", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
bunifuCustomLabel_Interpret.ForeColor = Color.FromArgb(224, 224, 224);
bunifuCustomLabel_Interpret.Location = new Point(20, 52);
bunifuCustomLabel_Interpret.Name = "bunifuCustomLabel_Interpret";
bunifuCustomLabel_Interpret.Size = new Size(98, 20);
bunifuCustomLabel_Interpret.Text = "Studio Tokyo";
//
// windowsMediaPlayer
//
AxWindowsMediaPlayer windowsMediaPlayer = new AxWindowsMediaPlayer();
windowsMediaPlayer.Dock = DockStyle.Bottom;
windowsMediaPlayer.Enabled = true;
windowsMediaPlayer.Location = new Point(0, 117);
windowsMediaPlayer.Name = "windowsMediaPlayer";
windowsMediaPlayer.OcxState = ((AxHost.State)(resources.GetObject("mediaPlayer.OcxState")));
windowsMediaPlayer.Size = new Size(912, 513);
windowsMediaPlayer.uiMode = "None";
//
// panel_currentlyPlaying
//
Panel panel_currentlyPlaying = new Panel();
panel_currentlyPlaying.Controls.Add(windowsMediaPlayer);
panel_currentlyPlaying.Controls.Add(bunifuCustomLabel_Titel);
panel_currentlyPlaying.Controls.Add(bunifuCustomLabel_Interpret);
panel_currentlyPlaying.Dock = DockStyle.Fill;
panel_currentlyPlaying.Location = new Point(0, 100);
panel_currentlyPlaying.Name = "panel_Playing";
panel_currentlyPlaying.Size = new Size(912, 630);
panel_Media.Controls.Add(panel_currentlyPlaying);
}
I think you may have forgotten to add the controls to the form.
Use this.Controls.Add(Control Item);
I have a UIScrollView into which I am creating and adding UILabels containing the results of a simple LINQ query.
I have set up a UISwipeGestureRecognizer within the loop that generates the labels (iOS: issues with UIGestureRecognisers vs Subviews says I need a new recogniser for each control - I'm assuming I can do with a UILabel the same as UIImageView for adding a recogniser) and then added the recogniser to the label.
When the view containing the UIScrollView is started, the scrollview works as expected, but the swipe isn't.
Caveat : only tried this on the simulator, my iPhone is acting up.
private void CreateViewHistory()
{
float xtext = 4f;
float y = 4f;
int c = 0;
var tv = tank.Events.OrderByDescending(t => t.Date).ToList();
tbiHistClearAll.Enabled = enableDelete;
//tgrRemove.AddTarget(this, new Selector("screenSwipe"));
//pgrRemove.DelaysTouchesBegan = true;
foreach (var e in tv)
{
var tgrRemove = new UISwipeGestureRecognizer()
{
NumberOfTouchesRequired = 1,
Direction = UISwipeGestureRecognizerDirection.Right,
};
tgrRemove.AddTarget(this, new Selector("screenSwipe"));
svHistoryEvents.PanGestureRecognizer.RequireGestureRecognizerToFail(tgrRemove);
string info = string.Format("{0} - {1}{2} ({3})\n{4} - {5}\n{6} - {7}\n{8} - {9}", e.EventType, e.Volume, AppDelegate.Self.db.getShortVolumeUnits(), e.Date.ToShortDateString(),
StringUtils.GetString("Sowcrop.Implement"), e.Implement != null ? e.Implement.ImplementType : StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.User"), StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.Notes"), !string.IsNullOrEmpty(e.Notes) ? e.Notes : StringUtils.GetString("Common.NonRecorded"));
var lbl = new UILabel()
{
UserInteractionEnabled = true
};
lbl = UICreation.MakeLabelWithTag(svHistoryEvents, new RectangleF(xtext, y, 320f, 90f), info, UITextAlignment.Left, UIColor.Black, false, 4, c);
lbl.AddGestureRecognizer(tgrRemove);
svHistoryEvents.AddSubview(lbl);
lblTemp.Add(lbl);
c++;
y += 94f;
}
UIUtils.ResizeScrollView(svHistoryEvents);
}
[Export("screenSwipe")]
public void SwipeRemove(UIGestureRecognizer s)
{
var swipe = s as UIGestureRecognizer;
var tv = tank.Events.OrderByDescending(t => t.Date).ToList();
var txt = swipe.View as UILabel;
switch (swipe.State)
{
case UIGestureRecognizerState.Began:
Console.WriteLine("Swipe began");
break;
case UIGestureRecognizerState.Changed:
Console.WriteLine("Swipe changed");
tv.RemoveAt(txt.Tag);
CreateViewHistory();
break;
case UIGestureRecognizerState.Ended:
Console.WriteLine("Swipe ended");
break;
case UIGestureRecognizerState.Cancelled:
Console.WriteLine("Swipe cancelled");
break;
}
}
MakeLabelWithTag generates a UILabel which can then be added to the scrollview.
Am I missing something here, or do I need to do something special as the label is held within a scrollview?
I've also tried what has been suggested at UISwipeGestureRecogniser in a UIScrollView, but still without success.
Found the problem and it's probably the dumbest thing I've encountered in a long time!
To get the swipe gesture to work within a scrollview, you have to first encompass whatever it is you want to add within a UIView and then add that to the scrollview.
To therefore get a swipe within a scrollview to work, you need to do the following
private void CreateViewHistory()
{
foreach (var i in svHistoryEvents.Subviews)
if (i is UIView)
i.RemoveFromSuperview();
float xtext = 4f;
float y = 4f;
int c = 0;
tbiHistClearAll.Enabled = enableDelete;
foreach (var e in tv)
{
var tgrRemove = new UISwipeGestureRecognizer()
{
NumberOfTouchesRequired = 1,
Direction = UISwipeGestureRecognizerDirection.Right,
};
tgrRemove.AddTarget(this, new Selector("screenSwipe"));
var view = new UIView(new RectangleF(xtext, y, 320f, 90f));
svHistoryEvents.PanGestureRecognizer.RequireGestureRecognizerToFail(tgrRemove);
string info = string.Format("{0} - {1}{2} ({3})\n{4} - {5}\n{6} - {7}\n{8} - {9}", e.EventType, e.Volume, AppDelegate.Self.db.getShortVolumeUnits(), e.Date.ToShortDateString(),
StringUtils.GetString("Sowcrop.Implement"), e.Implement != null ? e.Implement.ImplementType : StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.User"), StringUtils.GetString("Common.NonRecorded"),
StringUtils.GetString("Common.Notes"), !string.IsNullOrEmpty(e.Notes) ? e.Notes : StringUtils.GetString("Common.NonRecorded"));
var lbl = new UILabel()
{
UserInteractionEnabled = true
};
lbl = UICreation.MakeLabelWithTag(svHistoryEvents, new RectangleF(0, 0, 320f, 90f), info, UITextAlignment.Left, UIColor.Black, false, 4, c);
view.AddGestureRecognizer(tgrRemove);
view.AddSubview(lbl);
svHistoryEvents.AddSubview(view);
lblTemp.Add(lbl);
c++;
y += 94f;
}
UIUtils.ResizeScrollView(svHistoryEvents);
}
[Export("screenSwipe")]
public void SwipeRemove(UIGestureRecognizer s)
{
var swipe = s as UIGestureRecognizer;
var txt = swipe.View.Subviews[0] as UILabel;
switch (swipe.State)
{
case UIGestureRecognizerState.Began:
Console.WriteLine("Swipe began");
break;
case UIGestureRecognizerState.Changed:
Console.WriteLine("Swipe changed");
break;
case UIGestureRecognizerState.Ended:
Console.WriteLine("Swipe ended");
tv.RemoveAt(txt.Tag);
CreateViewHistory();
break;
case UIGestureRecognizerState.Cancelled:
Console.WriteLine("Swipe cancelled");
break;
}
}
It is not possible to add just a UILabel and have the swipe act on that, it has to be on a UIView with the label as a subview to it.
Hi, I have a windows forms application written in c#. I use tablelayoutpanel that have 5 rows and a column. My question is how could we add red columns and row (they are shown in red color in the picture) into just row 3 in runtime/dynamically ? And how can we reach later to be able to add controls (labels, textboxes, buttons..) into them?
Thanks for advices..
Here an example :
private void GenerateControls()
{
TableLayoutPanel tableLayoutPanel1 = new TableLayoutPanel();
Button button1 = new Button();
Button button2 = new Button();
PictureBox pictureBox1 = new PictureBox();
TextBox textBox1 = new TextBox();
tableLayoutPanel1.SuspendLayout();
// tableLayoutPanel1
tableLayoutPanel1.ColumnCount = 2;
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutPanel1.Controls.Add(button2, 1, 0);
tableLayoutPanel1.Controls.Add(button1, 0, 0);
tableLayoutPanel1.Controls.Add(pictureBox1, 0, 1);
tableLayoutPanel1.Controls.Add(textBox1, 1, 1);
tableLayoutPanel1.Location = new System.Drawing.Point(12, 12);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 20));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 30F));
tableLayoutPanel1.Size = new System.Drawing.Size(388, 301);
tableLayoutPanel1.TabIndex = 0;
tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint);
// button1
button1.Dock = DockStyle.Fill;
button1.Location = new System.Drawing.Point(3, 3);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(188, 144);
button1.TabIndex = 0;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
// button2
button2.Dock = DockStyle.Fill;
button2.Location = new System.Drawing.Point(197, 3);
button2.Name = "button2";
button2.Size = new System.Drawing.Size(188, 144);
button2.TabIndex = 1;
button2.Text = "button2";
button2.UseVisualStyleBackColor = true;
// pictureBox1
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new System.Drawing.Point(3, 153);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new System.Drawing.Size(188, 145);
pictureBox1.TabIndex = 2;
pictureBox1.TabStop = false;
//pictureBox1.Image = Image.FromFile(#"C:\somepic.jpg");
// textBox1
textBox1.Dock = DockStyle.Fill;
textBox1.Location = new System.Drawing.Point(197, 153);
textBox1.Multiline = true;
textBox1.Name = "textBox1";
textBox1.Size = new System.Drawing.Size(188, 145);
textBox1.TabIndex = 3;
Controls.Add(tableLayoutPanel1);
tableLayoutPanel1.ResumeLayout(false);
tableLayoutPanel1.PerformLayout();
}
This void will manipulate borders
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (e.Column == 0)
{
var rectangle = e.CellBounds;
rectangle.Inflate(-1, -1);
ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.All); // 3D border
}
else if (e.Column == 1 && e.Row == 0)
{
var rectangle = e.CellBounds;
rectangle.Inflate(-1, -1);
ControlPaint.DrawBorder(e.Graphics, rectangle, Color.Red, ButtonBorderStyle.Dotted); // dotted border
}
}